up vote 5 down vote favorite
1
share [g+] share [fb]

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?

link|improve this question

70% accept rate
feedback

3 Answers

up vote 4 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.

link|improve this answer
feedback

Or if you prefer the commandline,

grep "my string of text" -R .

You'll need to be (or get) familiar with grep.

Hm. Can't get to my OS X system to double check this, but another way to do it if OS X's grep doesn't support -R would be:

find . -type f -print0 | xargs -0 grep "my string of text"
link|improve this answer
1  
It supports -R just fine, and there's no slash in "OS X." – Hasaan Chop Nov 19 '09 at 20:31
Yeah, that's OS/2. – Rich Bradshaw Nov 19 '09 at 21:17
Heh. I was tempted to edit it to "OS 2" ;) Fixed, thanks. – retracile Nov 19 '09 at 22:54
Also, it is “Mac OS X”, unless you mean to include the iPhone/iPod touch OS. – Chris Johnsen Nov 20 '09 at 6:53
feedback

In the upper right hand corner of your screen: [Spotlight][1] Or, [BBEdit][2] supports great search, too, in files and folders.

[1]: Mac 101: Spotlight

[2]: BBEdit

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.