Copy all files matching pattern from dir and subdirs into a single dir
If I wanted to copy all *.so
files from src
to dst
I'd do:
cp src/*.so dst
However, I want to copy all *.so
files from src and it's subdirs into dst
. Any clues?
Solution 1:
Try:
find src/ -type f | grep -i so$ | xargs -i cp {} dst
Solution 2:
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