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?
You can't do this from the spotlight icon in the menu bar. But you can do it with spotlight:
Navigate to the folder in the finder.
Type your search in the search bar on the top right of the folder.
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.
mdfind 'kMDItemTextContent="*text*"c' -onlyin ~/Notes/
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.
Navigate to the folder you want to search if you have one.
Enter the term you want to search in the search bar in the upper right hand corner. You may need to stretch out the window to see it.
After you start typing or press enter you'll see a section below the search box to the left that says,
Search: This Mac "Your Folder" Shared
If you want to search your whole computer click on "This Mac". Otherwise click on the folder name next to it. It may already be selected.
To the right side of those options is a "Save" button with a plus sign next to it.
Click the plus sign. You'll see two drop down lists. In the first one select "Kind". In the second choose "Any" or "Text .
Choosing "Any" may find more matches, while "Text" will find files Mac OS X determines fall under the category "Text".
The number of search results will appear at the footer if the footer is shown.
FYI I've noticed that sometimes it takes time to do a search and sometimes there is no indication Finder is doing anything. I wouldn't wait too long but if you're searching a small folder it should be very quick. If searching your Mac it may take up to a minute or more.
Nota bene: To find an exact phrase enclose it in quotes.