macOS Terminal – How to Make ‘grep’ Work Like in Ubuntu

compatibilitysearchterminal

I tried to use grep to match one pattern on the terminal, but n
o any result comes out.

$ grep -R 'networks'
grep: warning: recursive search of stdin

I knew grep on macOS is based on BSD while grep on Ubuntu is based on GNU.

How to make 'grep' work on macOS like in Ubuntu?

Best Answer

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' .