Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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 trying to execute double search within files and return file names.

I'm using

find ./ -iname '*txt' | xargs grep "searchtext" -sl

to find file names with 'searchtext' in them.

Command is returning a list of files.

How can I find "othersearchtext" in those already found files and show them in the same fashion?

share|improve this question
It's fine if the answer is below. Please don't add an answer to your question. Thanks! – slhck Nov 23 '11 at 9:59
up vote 5 down vote accepted

Feed the result to another grep by using backticks or equivalent $().

If you want to keep the intermediate list, use tee

grep -l oranges $(find . -name "*txt" | xargs grep -l apples | tee apples.txt)
share|improve this answer
Thanks! grep -l "othersearchtext" $(find . -iname '*txt' | xargs grep "searchtext" -sl) – wormhit Nov 23 '11 at 10:04

You can chain xargs grep …:

find . -iname '*txt' | \
    xargs grep -l "searchtext" | \
    xargs grep -l "othersearchtext" | \
    xargs grep -l "yetanothersearchtext"
share|improve this answer

This bash will search multiple strings in given folder recursively and return filenames


findfiles /var/www/ php searchText1 searchText2 searchText3 searchText4

bash: findfiles



CMD="find $DIR -iname '*.$EXT' | xargs grep -l '$3' | xargs grep -l '$4' | xargs grep -l '$5' | xargs grep -l '$6' | xargs grep -l '$7' | xargs grep -l '$8' | xargs grep -l '$9'"

eval $CMD
share|improve this answer

Your Answer


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.