66

I'm using rsync to recursively sync a remote folder tree that looks something like this:

/folderA/a1/cache
/folderA/a1/cache/A1
/folderA/a1/cache/A2
/folderA/a1/somefolder
/folderA/a1/someotherfolder
/folderA/a2/somefolder/cache
/folderB/cache/
/folderB/b1/somefolder/cache
/folderB/b1/somefolder/yetanotherfolder/cache
/folderB/b1/somefolder/yetanotherfolder/cache/B1
/folderB/b1/somefolder/yetanotherfolder/cache/B2

I don't know what the folder tree will look like and it will change over time. So what I want to be able to do is recursively rsync the above but exclude the folder "cache" and any sub folders it contains:

/folderA/a1
/folderA/a1/somefolder
/folderA/a1/someotherfolder
/folderA/a2/somefolder
/folderB/
/folderB/b1/somefolder
/folderB/b1/somefolder/yetanotherfolder/

Any suggestions?

ivanleoncz
  • 487
  • 2
  • 7
  • 19
TheEdge
  • 763
  • 1
  • 5
  • 7

1 Answers1

103

You want the --exclude flag. For example, a local rsync:

rsync -a --exclude cache/ src_folder/ target_folder/

It really is that simple -- that exclude rule will match a directory named "cache" anywhere in your tree.

For more information, look for "--exclude" and the "FILTER RULES" section on the rsync man page:

http://www.samba.org/ftp/rsync/rsync.html

if you only want ONE cache directory like a1/cache then you would do:

--exclude 'a1/cache'
Trevor Boyd Smith
  • 3,772
  • 12
  • 36
  • 44
Jander
  • 16,272
  • 6
  • 50
  • 66