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

1 Answer 1


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


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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