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?
5 Answers
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.
7Another possibility:
find /path/to/search -name \*.doc -print0 | xargs -0 cp --target-directory=/destination/pathThis 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)
1On solaris you can use the following:
find /path/to/search -name "*.doc" -exec cp {} /destination/directory \; Find the files owned by user kelly, and copy them to a catalog: /opt/dir
# cd (into /path to copy files) e.g. cd /opt/
# mkdir dir (where you want to copy the files)
# find / -user kelly -exec cp -rfp {} /opt/dir/ \; To generalize you question from ".doc" to ".jpg" or other binary image files you'd need additional open source tools, like tagim and recoll.
tagim will tag your images with key words (or ratings) and then you can sort/filter them using recoll and flow the list to cp using xargs to plug them together:
recollq 'ofJoe ext:jpg' | xargs cp --target-directory=~/Photos/ofJoe