Recursive copy to relative destination paths
Actually it also works with cp, what you want is the --parents flag.
cp --parents `find /path/src \( -name "*.jpg" -o -name "*.gif" \)` /path/target
In theory -P
is synonyms with --parents
, but that never worked for me.
You can use rsync for this, e.g.
$ rsync -avm /path/src/ /path/dest/ --include \*/ --include \*.jpg --include \*.gif --exclude \*
Just to clarify the above:
-avm # recursive, copy attributes etc, verbose, skip empty directories
/path/src/ # source
/path/dest/ # destination (NB: trailing / is important)
--include \*/ # include all directories
--include \*.jpg # include files ending .jpg
--include \*.gif # include files ending .gif
--exclude \* # exclude all other files