I would like to mirror only specific files (for example *.jpg), but rsync creates empty directories on the destination host that don't have any *.jpg files in them.

My syntax is:

rsync -arv  
      --include '*/' 
      --include '*.flv' 
      --exclude '*' 
      host_source/ host_dest/

I try to create a file with all paths and file pattern matching *.jpg:

    find source/ -iname *.jpg > myfiles.txt  
/* and I use "sed" to filter the parent path to be OK */

So, now I run:

rsyn -ar --files-from=myfiles.txt host_source/ host_dest/

That works fine; no empty directories are created on "host_dest", but now if there are some files on "host_dest" that should be deleted on "host_source", rsync doesn't delete them.

So how do I tell rsync to "look" ONLY for the file pattern and not create empty directories on the host_dest?

Thanks a lot for answers before I go crazy :)


man rsync:

-m, --prune-empty-dirs      prune empty directory chains from file-list
  • yes !, i think it was the great direction... i dont see this option before, perhaps from new version of rsync. but to use with prudence !! i must make lot of test, but it was the answer with something like: rsync -a -m --del -vv --include='*.jpg' --include="*/" --exclude "*" host_source/ host_dest/ – thierryForum Feb 4 '13 at 15:14

Try removing the recursive option from the command line

rsync -a --files-from=myfiles.txt host_source/ host_dest/

  • nothing change... if there is some old *.jpg on "host_dest" they dont be deleted... – thierryForum Feb 4 '13 at 14:18
  • That's correct, to make your dest directory match exactly your source you will have to add the --delete option to delete the extraneous files. You should really take a few mins to read the man page. and @sparkle is also correct about pruning empty directories. Please indicate if this answers your question. Thanks. – X Tian Feb 4 '13 at 14:37
  • i read the man :) i have lot of process with rsync... do you really read my first question :) the problem was not how to delete file on the dest host, or how to send pattern file but a mixing of that whitout creating folder structure that dont be necessairy on the dest. but thanks a lot to you to search answer me. i think that the good direction was in the next answer and the "--prune-empty-dirs" that a dont see in my previeus version of rsync – thierryForum Feb 4 '13 at 15:24

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.