Find document files and copy them to another directory
This is a bit of a basic question but I'm trying to copy all .doc files I find in a directory and copy them to another directory.
I know each command:
find -name '*.doc' .
and:
cp filename location
How can I combine the two commands?
Solution 1:
find /path/to/search -name "*.doc" -exec cp {} /path/to/copy/to \;
If there are a lot of .doc files this is your best option to avoid hitting the character limit.
Solution 2:
Another possibility:
find /path/to/search -name \*.doc -print0 | xargs -0 cp --target-directory=/destination/path
This cuts down on the number of invocations of the copy command when compared to find -exec (should be noticeably faster if you have a huge number of files)