Tail -f + grep?

The tail has the following parameters:

-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 would like only grep for something in the tail output.

 tail -f <FILE> | grep <SOMETHING> 

The problem is that grep is only started once and executed. No other way out occurs. How can I make grep run correctly with -f ?

+7
linux unix bash grep tail
source share
2 answers

You will find another useful question: How is the "grep" continuous stream?

Turn on grep string buffering.

 tail -f file | grep --line-buffered my_pattern 
+30
source share

If it is a log file, it can be rotated. Then it will stop providing data.
This will not stop if the file is rotated.

 tail --follow=name /var/log/syslog | grep "some data" 
+6
source share

All Articles