2011-04-11

Recursive rsync, only specific file types

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