find and copy file using Bash [duplicate]
Solution 1:
I would recommend using find
's -exec
option:
find . -ctime 15 -exec cp {} ../otherfolder \;
As always, consult the manpage for best results.
Solution 2:
I usually use this one:
find . -ctime -15 -exec cp {} ../otherfolder/ \;
Solution 3:
You can do it with xargs
:
$ find . -ctime 15 -print0 | xargs -0 -I{} cp {} ../otherfolder
See also grep utility in shell script.
Solution 4:
If your cp
is GNU's:
find . -ctime 15 -print0 | xargs --no-run-if-empty -0 cp --target-directory=../otherfolder