Easy coloured tail output

As part of my job I’m often watching the output of a tail -f <filename> command run down my terminal window… and on my development and quite testing machines this is all well and good.

But what if the system is a pretty busy one? Well here it can be hard to spot the messages that might be of interest to you. And that is why I use a little trick to highlight a specific word in the output.

How to highlight words in tail output?

1) Basically add the following lines to your .bashrc  file

ctail(){
  tail -f $1 | perl -pe 's/'$2'/\e[1;31;43m$&\e[0m/g'
}

This adds a function available to you in bash that can be then be used to do exactly what you want. Say for example you want to highlight all instances of Error when tailing a file called foo.txt you can run the following.

ctail foo.txt Error