Wednesday, October 10, 2007

copy files with extension

I was looking for a command to copy all of the files with a given extension from one directory to another.  I know I could pipe the output of find to xargs where cp would be run, but you have to take special care to escape the paths. 


Here is a way to do the same thing with rsync:

rsync -azvE -r -m --include "*/" --include "*.mp3" --exclude "*" --verbose --progress /source/path/ /destination/path/

1 comment:

  1. Isn't 'find -print0 ... | xargs -0 ...' what you want to avoid having to escape paths? -print0 prints the output as one giant string with 's between filenames, and then the -0 to xargs tells it to read in the string in the same format. That way, you can easily work with pathnames that have weird characters (spaces!) in them.