Tuesday, November 13, 2007

How to 'grep' in color

Have you ever had to grep for words in a log file or document and wish they jumped out at you? Well here's a real easy way to accomplish this by using alias.

Modify the .bashrc file in your home directory by adding the following line:

alias grep='grep --color=auto'

Save the file and log out and back in again. If you don't want to logout just type the above on the command line and hit enter. Now grep a log file for a keyword and see what comes back! Here's what I get when I grep on .i386 in the /var/log/messages file

[root@testbox ~]# cat /var/log/messages|grep i386

Nov 13 07:07:54 testbox yum: Updated: gnome-python2-extras - 2.19.1-10.fc8.i386
Nov 13 07:08:01 testbox yum: Updated: elfutils-libelf - 0.131-1.fc8.i386
Nov 13 07:08:03 testbox yum: Updated: link-grammar - 4.2.5-1.fc8.i386
Nov 13 07:08:27 testbox yum: Updated: tomboy - 0.8.1-3.fc8.i386
Nov 13 07:08:28 testbox yum: Updated: gnome-python2-libegg - 2.19.1-10.fc8.i386

No comments: