Tail -f + grep?

Sten Kin picture Sten Kin · Apr 30, 2014 · Viewed 48.6k times · Source

Tail has the following options:

-f      The -f option causes tail to not stop when end of file is reached, but rather to wait for additional data to be appended to the
             input.  The -f option is ignored if the standard input is a pipe, but not if it is a FIFO.

I'd like to only grep for something in the tail output.

tail -f <FILE> | grep <SOMETHING> 

Issue is it only run grep once and is done. No other output happens. How can I make grep run correctly with the -f?

Answer

Sunny Patel picture Sunny Patel · Apr 30, 2014

You will find another SO Question helpful: How to 'grep' a continuous stream?

Turn on grep's line buffering mode.

tail -f file | grep --line-buffered my_pattern