Possible Duplicate:
How do I find text within a file and have it search multiple subfolders?

I would like to find out all the files under mydir/ directory whose content contains the string "apple". How can I do this?

  • This has been covered before. Have you performed a search before asking? – enzotib Nov 16 '11 at 10:28
  • Yes, I tried "gerp "apple"" but it search for all the files in my Ubuntu system which takes a long time. – Mellon Nov 16 '11 at 10:29

Maybe one of those

cd mydir ; grep -lr apple *


find mydir -type f | xargs grep -l apple
| improve this answer | |
  • What does * starnd for in command "grep -lr apple * "? – Mellon Nov 16 '11 at 10:41
  • * is target of grep command. It will expand to every name in current folder. – bbaja42 Nov 16 '11 at 13:41
  • It is funny, when I execute the command find . -type f | xargs grep -l t\.test in a directory it will work and when I apply the same command on the parent directory, it returns xargs: unterminated quote – 3nrique0 Sep 4 '14 at 8:45
  • Maybe, you have files with quotes or blanks in the name. Using "find mydir -type f -exec grep -l apple '{}' \;" might help. – ddeimeke Sep 9 '14 at 7:02

There is no need to use find actually, grep can do all that stuff.

grep --recursive --ignore-case --files-with-matches "apple" mydir/
| improve this answer | |
  • This only works with GNU grep, which is the default on Linux but not on Unix (AIX, HP-UX, Solaris, ...). – ddeimeke Sep 5 '14 at 14:15

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