56

I recently found that on Mac OS X I can set this up in my shell ~/.profile so that when I use grep it will print the matches in color (white one red).

alias grep='GREP_COLOR="1;37;41" LANG=C grep --color=auto'

But setting up an alias seems like kind of a hack way to do this. Previously I had tried with no luck:

export GREP_COLOR=always           # works fine in Linux

And then I also tried:

export GREP_COLOR="1;37;41"

Is there a better way to do this than setting up an alias?

cwd
  • 18,788
  • 43
  • 123
  • 162

2 Answers2

86

Per Grep_color on mac as suggested by @lupincho, this seems to work fine and does not use an alias:

export GREP_OPTIONS='--color=always'
export GREP_COLOR='1;35;40'
0

On macOS Catalina with grep (BSD grep) 2.5.1-FreeBSD I use the --colour argument when calling grep to activate highlighting.

grep --colour thon /usr/share/dict/words

I found this option when I ran 'man grep' after finding this thread. It seems odd the spelling of the argument is '--colour', and not '--color'. This command prints the results with text highlighted in red.