Sometimes you want to mirror a file tree, except you only want files matching a certain pattern (e.g. *.jpg). Rsync can do it, but the syntax isn't obvious. You need to tell rsync to include directories recursively, and to include the filetypes you want, and to ignore the rest. Here's an example:
rsync -Pav \ --include '+ */' --include '*.jpg' --exclude '- *' \ /path/to/olddir /path/to/newdir
Excellent, This solved a huge problem for me.
ReplyDeleteThanks a lot!!
/AB from Sweden
You don't need the -pr in there. The -a (archive, and implies -rlptgoD ...... so a bit of duplication.
ReplyDeleteThanks for the --include!
I just needed this again. In revisiting the post, I went ahead and changed -pavr to -Pav, which I usually use now. Thanks for the tip, Anonymous(2).
ReplyDeleteUnfortunately not quite what I wanted, as it will still rsync a directory even though it does contain any matching files
ReplyDeleteUnfortunately not quite what I wanted, as it will still rsync a directory even though it doesn't contain any matching files
ReplyDeletei need to copy only *.js to new folder, but, without folder tree.
ReplyDeleteEx:
ab/
ab/c/c.js
ab/c/d/d.js
ab/c/d/e/e.js
to
new/c.js
new/d.js
new/e.js
some can help me ?