Copying all files of specific type to a specific folder using Mac's Terminal

How can I copy all files of specific type to a specific folder using Mac's Terminal.

find . -name '*.STY' -type f -print0 | xargs -0 -I '{}' /usr/bin/rsync -avR "{}" "./styleFiles_chekad/"

Above shell script does the job and keeps the folders intact. What if I don't want the subfolders and want to have all the files right in the "styleFiles_chekad"? However, it is very complicated. Is there an easier way to do this? The following command does not work!

cp . -name '*.STY' styleFiles_chekad/

Any help would be greatly appreciated.

PS. Anyone can recommend a good resource for bash scripting?


Solution 1:

You should be able to just run

t=${TMPDIR:-/tmp}/target
mkdir "$t"

find . -type f -name '*.STY' -exec cp {} "$t"/ \;

mv "$t"/* ./styleFiles_chekad/
rmdir "$t"

The idea behind using a temporary directory is to prevent find from also copying the files it already moved into ./styleFiles_chekad/.