Search For String Or Text In Files On Mac OS and Windows

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" *

On Windows 10, a similar query can be performed with the findstr command. Once you navigate to the directory in a command prompt, replace “query” below with your desired search string.

findstr /S /C:"query" *

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

You might also like

Leave A Reply

Your email address will not be published.