≡ Menu

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

  •  
  •  
  •  

Very simple.

Add “–color” to your command

Example:

grep –color localhost /etc/hosts

127.0.0.1               loopback localhost   # loopback (lo0) name/address

 

The string “localhost” will appear in RED.

Note:

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