Search specific text in MacOS

Thursday, 20th September, 2018

Spotlight search is great if you’re looking for file or folder names. But to search for specific words inside text or code files in a folder, the following command line method is much more effective.

Step 1: Open the Terminal app, use the cd command to navigate to the folder where you want to search for your desired text or file name.

cd ~/Deb/Sites/project1/wp-content/themes/twentyseventen/

Step 2: Use the grep command to search inside this folder & folders further inside it.

grep -ir 'space_below' .

MacOS command grep

Here space_below is the word you are looking for. You can also search for text with quotes such as class or ID names by doing 'class="container"'

Notice the quotes & the dot in the 2nd step, they are required. This should be particularly useful for developers and writers who deal with text & need to find very specific ones.


If you have any comments or questions regarding this post then please email me, I would love to hear from you.