Page 1 of 1

MacOS – How to search file content from command line (Terminal)

macOS – How to search file content from command line (Terminal)

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.
Examples: "MacOS X - Your question", "MS Word - Your Tip or Trick".

Please note that switching to another language when reading a post will not work!
Posts will not have a translated counterpart.




RSS Feed

Home Forums Software MacOS X Software macOS – How to search file content from command line (Terminal)

This topic contains 0 replies, has 1 voice, and was last updated by  hans 5 days, 2 hours ago.

Viewing 1 post (of 1 total)
  • Author
    Posts
  • 11118

    hans
    Keymaster

    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 …

Viewing 1 post (of 1 total)



You must be logged in to reply to this topic.