hari
hari

Reputation: 1439

Shell Piping the data in middle of another command

If I need to have scripts like below:

find -name 'lib*.so' | xargs cp <files> ~/libs/.

Where < files > is the file which I found from the previous find command. Basically i want to pipe the data not just at the end but some where in the middle. (Some thing like $1 ???)

I understand I can have small sh file, where I can have this in a variable and use For loop & use that variable.... But what I want is simple one as I explained above. Where simple tasks can be accomplished easily.

Note: The script above is only a indication of type of Problem and the actual problem.

Let me know if this kind is possible.

Upvotes: 0

Views: 306

Answers (3)

Jonathan Callen
Jonathan Callen

Reputation: 11611

You can do this using find only, without having to spawn cp(1) for each file by doing:

find -name 'lib*.so' -exec cp -t ~/libs {} +

Note that this only works with GNU cp and a POSIX 2008 compliant find, like GNU find.

Upvotes: 1

ajreal
ajreal

Reputation: 47331

If you just want to do copy

find -name 'lib*.so ' -print0 | xargs -r0 cp --target ~/libs/

Upvotes: 1

brain
brain

Reputation: 2517

I hope I understand what you're trying to do here...

You can do this using find only.

find -name 'lib*.so' -exec cp {} ~/libs/ \;

Upvotes: 0

Related Questions