Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

G'Day,

I am using rsync to recursively sync a remote folder tree that looks something like the following:

/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 so that I ultimately end up syncing:

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

Any suggestions?

share|improve this question
    
See also an rsync filter tutorial. – Gilles Jan 13 '11 at 20:35
up vote 20 down vote accepted

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

rsync -a --exclude cache/ a/ b/

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

share|improve this answer
    
Doh!!. Thanks it is the simple answers that I like best :-) – TheEdge Jan 16 '11 at 0:38
1  
What about not anywhere in the tree? Like, only exclude a/cache. UPD See this answer – x-yuri Nov 12 '15 at 15:50
    
Also --exclude /cache/ (with the leading /) will only exclude a/cache directory, not any directory named cache. – Amir Ali Akbari Dec 19 '15 at 13:07
    
Why a/ b/ in the above command line, what does it mean? – Danijel Dec 24 '15 at 9:13
    
@Danijel: a/ is the directory we're syncing (or copying) from; b/ is the directory we're syncing into. – Jander Dec 25 '15 at 4:48

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.