How to exclude multiple directories with rsync?
OK I feel really dumb. Before I even posted this question my friend showed me how to do it and it is really simple. To exclude multiple directories you just use multiple --exclude=path
switches. So my command above properly written is as follows:
rsync -arv --exclude=.ccache --exclude=build /home/ben /media/ben/thumbdrive/
Note: Use relative paths with exclude. The paths are relative to the source directory, here /home/ben.
When having multiple directories and/or files to exclude, make a text file and use the --exclude-from
switch. Make a file called exclude_me.txt
and in it list your exclusions.
Example (/home/ben/exclude_me.txt
):
.ccache
build
.java
.gvfs
.xsession-errors
Then your rsync would look something like this:
rsync -arv --exclude-from='/home/ben/exclude_me.txt' /home/ben /media/ben/thumbdrive/
This is some information on filter rules that may help:
-
/dir/
means exclude the root folder/dir
-
/dir/*
means get the root folder/dir
but not the contents dir/
means exclude any folder anywhere where the name containsdir/
Examples excluded:
/dir/, /usr/share/directory/, /var/spool/dir/ /var/spool/lpd/cf
means skip files that start withcf
within any folder within/var/spool/lpd
Also see the filter rules section on the man page.
You can also exclude multiple paths within curly braces:
rsync -arv --exclude={.ccache,build} /home/ben /media/ben/thumbdrive/