Unix geek question: Recursively copying only specific files?
I want to back up all of my purchased iTMS music to DVD. What I essentially want to do (even though it doesn't actually work in this form) is this:
cp -R /path/to/my/music/*.m4p /path/to/the/dvd
The problem is that the -R only works if the source parameter is a directory -- a glob expression won't do. Without -R, the glob works, but doesn't recurse.
I'm not enough of a Unix geek myself to know the magical one-line command (which I'm sure exists) that does a recursive find or something like that and pipes the find output into some other command like awk or whatever. My attempts to Google for a solution only turn up what I already know -- as if the -R of and by itself is such an awe-inspiring guru trick.
cp -R /path/to/my/music/*.m4p /path/to/the/dvd
The problem is that the -R only works if the source parameter is a directory -- a glob expression won't do. Without -R, the glob works, but doesn't recurse.
I'm not enough of a Unix geek myself to know the magical one-line command (which I'm sure exists) that does a recursive find or something like that and pipes the find output into some other command like awk or whatever. My attempts to Google for a solution only turn up what I already know -- as if the -R of and by itself is such an awe-inspiring guru trick.
Comments
find . -name '*.m4p' -print
That gets me the paths to all of the music files I want. I think if I played around a little more, I might get as far as copying all of these files from different directories into one flat directory.
The Unix mojo that I lack is how to use the find output for two different things: both as-is for the source of the original file, and modified to become the proper destination path, especially in such a way as to automatically create any directories that don't originally exist within the target directory.
The above will get you the flat files.
If you want directories recreated as well, to reproduce a hierarchy, you might want to try using rsync (grab the HFS resource fork aware one from macupdate.com, instead of the default one). It will do what you want with enough tweaking.
Originally posted by Kickaha
find /path/to/music -name "\\*.mp4" -exec cp {} /path/to/dest \\;
Ah... you must have posted this while I was typing my message about the piece of the puzzle I had found. Thanks.
Wouldn't the above put all of the copied files in the same directory, instead of recreating the directory structure? I just found this recommendation for what I want to do:
find . -name "*.pdf" -print | cpio -pvdum /newdir
Will have to remember the cpio trick, thanks.