Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I have a large directory tree with lot of files like;

/abc2/def/thumbnail.jpg
/abc1/def/thumbnail.jpg
/abc1/def/geh/someothertextfile.txt
/abc1/defe/geh/thumbnail.jpg

I would like to rsync all those directories and files that match thumbnail.jpg to another tree.

I tried;

rsync -r --exclude-from=/tmp/exclude src dst

with exclude file containing;

# cat /tmp/exclude 
+ /thumbnail.jpg
+ thumbnail.jpg
+ /**/thumbnail.jpg
+ **/thumbnail.jpg
- *

but this does not match any.

share|improve this question
add comment

3 Answers

up vote 0 down vote accepted

use find

find / -name "thumbnail.jpg" -exec rsync -avz --compress --progress {} dst \;
share|improve this answer
    
that looks like it would work. though if you had a bazillion files in src and dst was a remote rsync module like serverXXX::modulename, then that would be kinda inefficient...? –  Tom H Jul 14 '10 at 9:32
add comment

ok, so actually RTFM always works in the end...

changing the command to;

rsync -r --prune-empty-dirs --exclude-from=/tmp/exclude src dst

and changing the exclude file to;

# cat /tmp/exclude 
+ */
+ thumbnail.jpg
- *

works like a charm.

share|improve this answer
add comment

Your problem is that the final - * excludes all directories (which tells rsync not just not to copy them but also not to traverse them). Use

+ thumbnail.jpg
+ */
- *

and pass --prune-empty-dirs on the rsync command line.

share|improve this answer
add comment

Your Answer

 
discard

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.