Welcome to the Tweaking4All community forums!
When participating, please keep the Forum Rules in mind!
Topics for particular software or systems: Start your topic link with the name of the application or system.
For example “MacOS X – Your question“, or “MS Word – Your Tip or Trick“.
Please note that switching to another language when reading a post will not bring you to the same post, in Dutch, as there is no translation for that post!
[Solved] macOS - How to search file content from command line (Terminal)
(@hans)
Famed Member Admin
Joined: 12 years ago
Posts: 2859
Topic starter
November 8, 2018 4:07 AM
So, in the past years most of us may have ran into issues of Spotlight being far from perfect (why did google Desktop disappear!?).
Sometimes I find myself needing to find a phrase, or piece of text; see in what file(s) this piece of text occurs ... and Spotlight is not finding it, and PathFinder (crap search as well) is not finding it either.
After a while I found a way to do this in Terminal, which seems VERY reliable.
The following will search the content of ALL files in the given path, for a given text:
grep -r 'yourtext' path
For example when I'm looking for what files contain the text 'addObserver', in my Lazarus Pascal directory, then this will give me the answer:
grep -r 'addObserver' ~/freepascal/lazarus/
Hope others find this useful as well ...