Find String in Files – How to Search for Exact String in Files on macOS Command Line

command linemacossearchspotlight

I tried all the recipes (double quotes, escaped double quotes etc.) in vain. I'm not interested in files containing any or all of these words, only the exact string. (EasyFind does the job.) I'm using macOS Catalina with zsh.

Is there a way to have mdfind detect an exact string, say "what I look for", in the content of files?

Best Answer

It might be easier to use tools dedictated for searching text within files, e.g. grep (part of macOS) or ag (brew install ag):

fgrep -r "Text to match" PATH
ag -F "Text to match" PATH