Friday, February 25, 2011

Using rsync to copy only certain extensions

I had a directory structure like this:
...
a/foo/bar/baz.txt
b/bar/asdf.jpg
c/qwerty/bletch.txt
...
and I wanted to rsync only the .txt files to my local machine:
a/foo/bar/baz.txt
c/qwerty/bletch.txt
There are lots of search results for the topic, but most didn't work right -- rsync -vv kept telling me that my --exclude="*" rule was excluding everything. This post gives the correct details. You need to explicitly include the directories you want, or just --include='*/', then --include='*.txt', then --exclude='*'. You may end up with a bunch of empty directories; I haven't figured out how to efficiently avoid that.

1 comment:

Anonymous said...

--prune-empty-dirs seems to do the trick so you don't get all those empty dirs