Sign up ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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

2 Answers 2

up vote 82 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 at 22:20
@Zlatty: grep is love, grep is life. – Ignacio Vazquez-Abrams May 4 at 22:23

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 at 11:44

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.