≡ Menu

How can I colorize Unix ‘grep’ command so that matching strings are highlighted ?

Very simple.

Add “–color” to your command


grep –color localhost /etc/hosts               loopback localhost   # loopback (lo0) name/address


The string “localhost” will appear in RED.


1. You need GNU ‘grep’ for this to work

2. Don’t use “GREP_OPTIONS” environment variable in your shell startup scripts to accomplish this. It can break several scripts.

More information can be found in this link: http://www.gnu.org/software/grep/manual/grep.html#Environment-Variables

{ 0 comments… add one }

Leave a Comment