尾巴-f + grep?

Ste*_*Kin 13 unix linux bash grep tail

Tail有以下选择:

-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.
Run Code Online (Sandbox Code Playgroud)

我只想something在尾部输出中进行grep .

tail -f <FILE> | grep <SOMETHING> 
Run Code Online (Sandbox Code Playgroud)

问题是它只运行一次grep并完成.没有其他输出发生.如何让grep正确运行-f

Sun*_*tel 42

你会发现另一个SO问题有用:如何'grep'连续流?

打开grep的线路缓冲模式.

tail -f file | grep --line-buffered my_pattern
Run Code Online (Sandbox Code Playgroud)


Jot*_*tne 7

如果这是一个日志文件,它可能会被轮换.然后它将停止提供数据.
如果文件被旋转,这将不会停止.

tail --follow=name /var/log/syslog | grep "some data"
Run Code Online (Sandbox Code Playgroud)