Super User is a question and answer site for computer enthusiasts and power users. 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 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 :)

share|improve this question

migrated from Feb 4 '13 at 10:48

This question came from our site for professional and enthusiast programmers.

man rsync:

-m, --prune-empty-dirs      prune empty directory chains from file-list
share|improve this answer
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/

share|improve this answer
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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .