How does Rsync synchronize hidden and excluded files? How does Rsync synchronize hidden and excluded files


The basic writing method of Rsync synchronization command

Rsync command options source directory target directory

If the source directory is written as / var / www /, all files in the directory will be synchronized to the target directory. If it is written as / var / www / *, the hidden files in the current directory (the folder name or file name starts with the “..”) will not be synchronized, but the hidden files in the subdirectory will still be synchronized.

If you need to exclude a file (or folder), you can use the–excludeTo specify, for example, the dir1 folder under the source directory needs to be excluded, which can be written as:

/usr/bin/rsync -vzrtopg –exclude=dir1 /var/www/src/ /var/www/dest

You can exclude multiple items at the same time, for example:

/usr/bin/rsync -vzrtopg –exclude=dir1 –exclude=dir2 /var/www/src/ /var/www/dest

In addition to the above methods, you can also use–exclude-fromTo specify, for example:

/usr/bin/rsync -vzrtopg –exclude-from=exclude.list /var/www/src/ /var/www/dest

The exclude.list file specifies the list to exclude, for example:


The meaning is to exclude all files and folders named by numbers under / var / www / dir1, / var / www / dir2 /, hidden files under / var / www / dir2 /, and all. SVN folders under / var / www, including. SVN folders in its subdirectories.

Be careful:Both exclude and exclude from are preceded by two minus signs. If one is omitted, the command line will not report an error, but the executed file or folder cannot be excluded.