Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I'm finding a bunch of files with find . -exec grep -l mypattern {} \;

What's the simplest, most elegant way to run a certain command separately on each of the resulting list of files?

share|improve this question
add comment

1 Answer

up vote 9 down vote accepted

To begin with, use:

grep -Rl mypattern .

directly instead of the find construct.

What is the certain command? Probably the best and most fail-safe way would be

grep -ZRl mypattern . | xargs -0 mycommand

Exactly what you want to do is up to xargs from here.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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