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?

link|improve this question

Seems like this question has been asked before...several times – aking1012 Jul 19 '11 at 14:03
feedback

2 Answers

up vote 5 down vote accepted

Try:

find src/ -type f | grep -i so$ | xargs -i cp {} dst
link|improve this answer
good solution...giving the +1, but I'm sure this question is a duplicate. Can't put my finger on the original at the moment though. – aking1012 Jul 19 '11 at 14:05
Brr. So there isn't an option in cp or something. Thanks! – Albus Dumbledore Jul 19 '11 at 14:10
1  
find can do pattern matching and execute commands. There's no need to pipe its output: find src/ -type f -name '*.so' -exec cp '{}' dst/ ';' – jaquer Jul 19 '11 at 15:44
Yes, it can, however it's often easier to read a pipeline, also the pattern matching capabilities of grep far outweigh the simple shell patterns used in the -name parameter to find. xargs is also far more powerful than the -exec parameter to find. – Mike Insch Jul 19 '11 at 15:51
Fair enough. It just seemed overkill for OP's question. – jaquer Jul 20 '11 at 15:14
feedback

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
link|improve this answer
Nice. Exactly what I hoped for :-) Still, I'll need to check it first. Thanks! – Albus Dumbledore Jul 19 '11 at 18:23
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.