How to exclude directories from source with --relative

Wayne Davison wayned at
Tue May 27 06:40:31 GMT 2008

On Mon, May 26, 2008 at 09:46:04PM -0700, Stuart Anderson wrote:
> # rsync -avn --relative --exclude b/ /tmp/source/./a/? /tmp/destination

That excludes all "b" dirs.  It's safer to exclude "/a/b/" (anchored and
fully specified).  The simple rule is to exclude the names that rsync
outputs via -v.

> 3) Try excluding a/, this does not work:
> # rsync -avn --relative --exclude a/ /tmp/source/./a/? /tmp/destination

That's because 'a' is an implied directory in the longer path that you
told rsync to transfer.  Implied directories can't be excluded, but
their attributes can be omitted via --no-implied-dirs.  If you don't
want it in the transfer, don't specify it (and if you're using wild-
cards, specify them in such as way as to avoid matching the dir you
don't want).


More information about the rsync mailing list