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'm using rsync to copy some files from a share to another.

Recursively, I need to:

  • Delete files at destination that were removed from the origin
  • Only sync php and js files
  • Exclude every other file type
  • Do not delete .svn/ directories at destination

If I use this:

rsync -zavC --delete --include='*.php' --include='*.js' --exclude="*" \
    /origiin /destination

Then rsync is not recursive because exclude="*" excludes all files but also folders

If I add --include="*/" then the .svn/ directory gets deleted (it also gets included)

How can I solve this mind blasting dilemma?

uname -a:

Linux tux 3.9.2-1-ARCH #1 SMP PREEMPT Sat May 11 20:31:08 CEST 2013 x86_64 GNU/Linux

rsync version:

rsync 3.0.9-6

Thanks in advance

share|improve this question
up vote 0 down vote accepted

Ok, after several tries I sorted this up:

rsync -vaiz --delete --exclude=.svn/ --include='*.php' --include='*.js' \
    --include='*/' --exclude='*' --prune-empty-dirs \
    --filter "protect .svn/" /origin /destination

Another approach

in case you don't mind syncing empty dirs, just:

rsync -vaiz --delete --exclude=.svn/ --include='*.php' --include='*.js' \
    --include='*/' --exclude='*' /origin /destination

The key was to --exclude=.svn/ before the --include's

share|improve this answer
Did you hardcode these values in a bash script or generate them? Another --filter question using bash. – rjt May 24 '13 at 20:57

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.