Copy all files matching pattern from dir and subdirs into a single dir
Try:
find src/ -type f | grep -i so$ | xargs -i cp {} dst
If you're using Bash, you can turn on the globstar
shell option to match files and directories recursively:
shopt -s globstar
cp src/**/*.so dst
If you need to find files whose names begin with .
,
and/or files in and under directories whose names begin with .
,
set the dotglob
option also (e.g., with shopt -s dotglob
).
You can set them both in one command:
shopt -s globstar dotglob
I tried the command suggested by Mike:
find src/ -type f | grep -i so$ | xargs -i cp {} dst
but it ended up with dumping all the files into directory dst
with their relative paths lost.
To keep the relative paths the command needs to be modified to this:
find src/ -type f | grep -i so$ | xargs -i cp {} dst/{}