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.

Mike Hudson

Mike Hudson is a Lead Cyber Security Analyst living and working in Kingston Upon Hull. With extensive experience in Microsoft and Apple technologies, ranging from desktop OS’s to Server OS’s and hardware. By day working as part of an infrastructure team, and by night ridding the world of IT issues through blog posts..

%d bloggers like this: