All notes

Best examples


Specify RULE file with either "--include-from" or "--exclude-from". They are the same.

The RULEs include:

+ include
- exclude
. merge
: dir-merge
H hide
S show
P protect
R risk
! clear

The RULE and pattern should be separated by either a space or an underscore.

Include parent directories before including

If the parent directories are excluded, rsync will never look into it, so even if you include a file or directory under it, the file or directory will never be included. For example:

+ b/c.txt
- *

The file c.txt will never be included, since its parent directory b is excluded, and rsync will just ignore b and its children wholy.

It is assumed that all files and directories are included. So you always need to put "- *" in the last to exclude all unspecified. Some suggests to use "--filter=-! */", which means excluding all non-directories ("!" means non, and "*/" means all directories), which is to say, all the directories in current working path will be included. In order to prevent including empty directories, it is suggested to add the option "--prune-empty-dirs".


With recent rsync, there comes the p modifier. A p modifier to a rule indicates that the rule is perishable, or, it is ignored in directories that are being removed. The common usage is to handle with the ".DS_Store" file. The text "--filter='-p .DS_Store'" tells rsync to exclude ".DS_Store" unless the file is the last file in a directory, so that removing the near empty directory will not be hindered by the file.

Hide rules and delete

This page says a combination of hide and protect rules equals to an exclude rule:

#exclude rule

#combined hide and protect
--filter='H /some/dir' --filter='P /some/dir'

Rsync FAQ

dup() in/out/err failed

kwakwaversal commented on 15 Sep 2016
@LondonAppDev @ctaorminainn I also had the dup() in/out/err failed error, but I managed to solve it.

I found that the issue was because I didn't have the ssh bundled with my Cygwin install. When you're installing Cygwin, it recommends you only install what you need. As such, I only selected rsync because I had a working ssh with my Windows git installation. As you've already guessed, they're not compatible!

The fix was to add Cygwin's version of ssh to the Cygwin installation, and for good measure, I removed the git PATH to make sure that rsync was using the ssh that was part of the same distribution as itself.

So the solution is to set the PATh.

How to include a subdir recursively


+ company1/  
+ company1/unique_folder1/***  
+ companyN/  
+ companyN/unique_folder1/***  

rsync -avzn                                        \
      --list-only                                  \
      --include-from '/path/to/new/include.txt'    \
      --exclude '*'                                \
      -e ssh    \


About CVS exclude

The exclude list is initialized to:

RCS SCCS CVS CVS.adm RCSLOG cvslog.* tags TAGS .make.state .nse_depinfo *~ #* .#* ,* _$* *$ *.old *.bak *.BAK *.orig *.rej .del-* *.a *.olb  *.o  *.obj
*.so *.exe *.Z *.elc *.ln core .svn/

then files listed in a $HOME/.cvsignore are added to the list and any files listed in the CVSIGNORE environment variable (all cvsignore names are delimited by whitespace).

Finally, any file is ignored if it is in the same directory as a .cvsignore file and matches one of the patterns listed therein. Unlike rsync's fil- ter/exclude files, these patterns are split on whitespace.

rsync -avzCh --partial --progress src user@remote:/path/to/des