Search For String Or Text In Files On Mac OS X

0

Sometimes, it’s the simple commands which are incredibly powerful.

I routinely need to search for a string (text, number sequence, hashtag, etc.) within a batch of files, but instead of opening each one and querying the contents, here’s a much simpler method on Mac OS X.

Use Terminal to navigate to the folder containing your files. Run the following command replacing “text to find” with the relevant query. The “-lr” flag will recursively search each file contained in that directory and subdirectories.

grep -lr "text to find" *

Your output will be a list of files containing the string you searched for. 🙂

 LEAVE A REPLY

Please enter your comment!
Please enter your name here