Home > How To's/Reviews > Search For String Or Text In Files On Mac OS X

Search For String Or Text In Files On Mac OS X

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. 馃檪

 LEGAL

My posts are not to serve as a replacement for recommendations provided by licensed physicians nor do they represent the opinions of Baylor College of Medicine or its affiliated institutions. Please read this site's Disclaimer and Terms of Use for more information.

ALSO CHECK OUT  

WordPress PHP Shortcodes For Yearly Post And Comment Counts

I wanted an easy way to calculate some end-of-year stats, so I put together a …

 DROP A LINE

Your email address will not be published. Required fields are marked *