Search file contents in OS X

20130330-212630.jpg

One of the powerful features of OS X built-in spotlight is its ability to search the contents of files for your search string.. However, for reasons yet unknown, I have found this functionality to sometimes be a little hit and miss..

Which is where Terminal comes in.. Using a single line terminal command OS X will rapidly return all the files containing the text you are looking for.

First of all, for this example you need to first set your current path in terminal to the folder containing the files you want to query.

Then type/copy & paste the following

So for example, should you want to find all the text files containing the word AppleScript, you would use the following command:

To expand of the example above, should you want to extend that and search sub folders all you need to do is add ‘r’ for recursive:

This will now return all text files in the folder and subfolder containing the term AppleScript.

Read More