Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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
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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .