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 find the find . -name "some-file" command very useful to list all files matching some file name in a folder. Is there anything similar I can use to list all files that contains string?

If you needed to find all files in a directory that had a certain string of text in it, what would you use?

share|improve this question
up vote 4 down vote accepted

If you don't need to search subdirectories:

grep -l "string" <pattern>

(<pattern> is a file glob pattern, eg *.txt)

share|improve this answer
Just found that out, hehe. Didn't know grep could work on directories as well. And if you add -r it will search subdirectories as well! For example grep -lr "string" . – Svish Apr 22 '10 at 14:01

Just in case you are using a system with a POSIX strictly compliant grep, ie which doesn't support the -r flag, but you still want to recurse in sub-directories, you can use this command:

find . -type f -name "*.txt" -exec grep -l string {} +
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.