Macos – How to grep with color in Mac OS X’s terminal

consolegrepmacmacosterminal

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?

Best Answer

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'