Apple - How to make 'grep' work like in Ubuntu?
When the -R
option is used, MacOS grep
requires you to explicitly give it a directory to search; for example, specify .
to recursively search the current directory:
grep -R 'networks' .
Long term, it's probably best to install the tools based on GNU or run Ubuntu virtually. Both are available for free.
brew install coreutils
(to run the brew
command you need to install homebrew from https://brew.sh) will put the GNU versions of the tools in your path. Look for the ggrep
command and possibly a standalone grep
package to install as the coreutils does tend to change over time what it includes.
(EDIT: Note that as of 2018, grep
specifically needs to be installed separately from coreutils
as follows:
$ brew install grep
$ ggrep sometext file.txt # Note the executable is called ggrep with two G's
and has a unique executable name ggrep
with two G's.)
Also searching here for GNU or coreutils will be helpful for context and tips/tricks.