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

Is there a way to search through all the text files in a folder (and subfolders) for a specific string or bit of text in Mac OS X?

share|improve this question

5 Answers 5

up vote 8 down vote accepted

You can't do this from the spotlight icon in the menu bar. But you can do it with spotlight:

  1. Navigate to the folder in the finder.

  2. Type your search in the search bar on the top right of the folder.

  3. There is a line above the results that says:

Search: This Mac "Your Folder Name"

Click on the name of your folder to restrict the search to the folder instead of the whole computer, which is what the default selection "This Mac" does.

Then click the gear icon, choose show search criteria, and change the kind to text files.

share|improve this answer
unfortunately this seems to do OR not AND, and some symbols are stripped out of queries I think. –  Aram Kocharyan Apr 20 '12 at 0:50
do you need to index your folder first ? –  jokoon Jun 28 '14 at 13:30
no, as long as the folder is normally indexed by spotlight –  ridogi Jun 30 '14 at 19:41

If you prefer the command line,

grep "my string of text" -R .

You'll need to be (or get) familiar with grep. Read man grep for more info.

share|improve this answer
In my .profile I created this helper : function findtext() { grep -ri "$1" . }. I use it like this : findtext toto where I want to start to search. –  Maxence Sep 17 at 15:46

Very powerful and fast

mdfind "text to find"

Description: Mac Dev Centre - The Power of mdfind

share|improve this answer

In the upper right hand corner of your screen: Spotlight

BBEdit supports great search, too, in files and folders.

share|improve this answer
mdfind 'kMDItemTextContent="*text*"c' -onlyin ~/Notes/

c ignores case. See this answer for an overview of the query format and other attributes.

grep -F what? -l -r ~/Notes --include *.txt

-F searches for fixed strings instead of regex. -l only prints the names of the matching files.

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.