Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I want to move some subset of files from dirA to dirB (let's say files with "blah" in the filename), but I want all the nested directories to be the same in the new location. How can I do that?

share|improve this question
    
possible duplicate of Rsync filter: copying one pattern only –  Gilles Apr 8 '11 at 20:14
add comment

2 Answers

The magic of rsync filter rules:

$ rsync -av --filter="+ */" --filter="-! *blah*" /source /dest

Consult the rsync man page for the details on filter rules, but here's the condensed version for this particular need.

--filter="+ */" means "include everything that is a directory"

--filter="-! *blah* means "exclude everything that does NOT include blah in the filename"

share|improve this answer
add comment

This worked for me:

rsync -ave 'ssh -p 22' --filter="+ */" --exclude="*_blah.blah" uid@555.55.555.55:/source/directory/ /destination/directory/

The -e switch defines rsync transfer protocol with port as -p 22. Also, the trailing / slashes are important to let the program know it's dealing with directories.

Thanks @pdo for the extra hours in my work day!

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.