Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

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

I have a tree of subdirs, some of which contain a file with the word "template" as part of the name. I want to rsync them to the same subdir tree in a different location.

eg: Source:


Intended destination:


This command didn't work; it put all the files in the base destfolder, rather than in the correct subdirectories:

rsync -av curfolder/*/*/*template* destfolder

So I think I need a filter something like this, but this isn't working (it seems to just sync everything):

rsync -av -f"+ *template*" curfolder destfolder
share|improve this question
Is there any particular reason why you do not accept my answer? – Niko S P Feb 26 '12 at 10:32
@NikoSP, thanks for your answer. It did work, however a link to some documentation explaining why it works would be the best possible answer, so if you can add that to your answer I'll accept it immediately. – Highly Irregular Feb 26 '12 at 18:03
i just added some explaination to it – Niko S P Feb 26 '12 at 18:42
up vote 1 down vote accepted

One way to do it:

rsync -av --include "*/" --include="*_template*" --exclude="*" --prune-empty-dirs curfolder/ destfolder/  

rsync man

what it does, expressed in words:

  1. include every folder
  2. include everything matching *_template*
  3. exclude everything else
  4. delete empty folders

The two includes are taking precedence over the exclude, so the exclude only matches everything the includes did not match.

share|improve this answer

Your Answer


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.