Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. 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 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

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

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

Your Answer


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.