Search code examples
linuxbashcopyfind

find and copy file using Bash


Anybody has an alternative way of finding and copying files in bash than:

find . -ctime -15 | awk '{print "cp " $1 " ../otherfolder/"}' | sh

I like this way because it's flexible, as I'm building my command (can be any command) and executing it after.

Are there other ways of streamlining commands to a list of files?


Solution

  • I would recommend using find's -exec option:

    find . -ctime 15 -exec cp {} ../otherfolder \;

    As always, consult the manpage for best results.