Linux quick tips – grep with color

Grep is tremendously useful utility for searching for text strings in files. It is one of those tools which once you learn how to use, you wonder how did you ever managed without it. However, grep can do more than just display the desired output, it can display it with colors. This may sound trivial, but depending on what you search, you can end up with a lot of content crammed up in your terminal window with no line breaks or indentation to help you read the text.

So, to make the output more readable, simply add –color option.

If you like this option so much that you start using it every time and like most people you don’t feel any pleasure in pounding your keyboard unnecessarily, you can add this alias to your ~/.bashrc (that is the .bashrc in your home directory):

alias grep='grep --color=auto'

Some Linux distributions (like Debian) already have this line, but it is commented. After you edit your .bashrc file you will need to log off and log in back again to activate these changes.

Read More