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'd like to find all files that contain a certain string of text. How would you do that in the Terminal?

share|improve this question
If you want a fast result, use Spotlight, though. Also if you want to find files that don't necessarily store text directly within the file such as PDF or ODF. – Joey Jul 13 '10 at 9:47
Good advice, but in my case I'm not sure the files are indexed since they are on network drivers. And also they are xml files belonging to a particular program. – Svish Jul 13 '10 at 10:09
up vote 116 down vote accepted
grep -r 'text goes here' path_goes_here
share|improve this answer
Awesome simple answer. Thanks! – Svish Jul 13 '10 at 9:51
Congrats on your 10K. – Dennis Williamson Jul 13 '10 at 14:31
I love the fact that nearly five years later, this response has saved the day. Thanks! – Zlatty May 4 '15 at 22:20
@Zlatty: grep is love, grep is life. – Ignacio Vazquez-Abrams May 4 '15 at 22:23
I would suggest a man grep to discover all the wonderful options of grep – Ludovic Kuty Jan 20 at 12:31

use spotlight

mdfind "text goes here"
mdfind -onlyin /home/user/Desktop -live "live update"

don't forget to look at:

man mdfind
share|improve this answer
Will this work for files that spotlight doesn't index (i.e. files inside hidden folders, system config files, etc)? – Accipheran Sep 10 '13 at 4:10
Grep doesn't seem to parse .xlsx files, but this worked out fine. Another easy example: mdfind -onlyin . "searchtext" – FvD Sep 2 '15 at 11:44
  1. Through Ack

brew install ack ack "text goes here"

  1. Through find

find . |grep "text goes here"

  1. Through grep

grep -RnslI "text goes here"

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.