Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. 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

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?

share|improve this question

marked as duplicate by Gilles, Michael Mrozek Nov 16 '11 at 22:25

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

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
up vote 2 down vote accepted

Maybe one of those

cd mydir ; grep -lr apple *


find mydir -type f | xargs grep -l apple
share|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/
share|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.