Find – List Files Containing a Particular Word in Their Text

file searchfindgrep

I would like to list the files recursively and uniquely that contain the given word.

Example: Checking for word 'check', I normal do is a grep

$ grep check * -R

But as there are many occurrence of this word, I get a lot of output. So I just need to list the filenames that contain the given search word. I guess some trick with find and xargs would suffice here, but not sure.

Any ideas?

Best Answer

Use the -l or --files-with-matches option which is documented as follows:

Suppress normal output; instead print the name of each input file from which output would normally have been printed. The scanning will stop on the first match. (-l is specified by POSIX.)

So, for you example you can use the following:

$ grep check * -lR
Related Question