【发布时间】:2014-06-17 05:18:19
【问题描述】:
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.
我只想在尾部输出中为something grep。
tail -f <FILE> | grep <SOMETHING>
问题是它只运行一次 grep 就完成了。没有其他输出发生。如何使用-f 使 grep 正确运行?
【问题讨论】:
-
我经常按照您的描述进行操作,而且效果很好。
grep命令在tail -f进程终止之前不会终止,但当然它不会产生任何输出,直到将包含该模式的内容附加到文件中。 -
我可以在多个平台上确认这一点。完全按照这里的描述使用tail+grep,我从来没有遇到过麻烦。您在哪个平台上遇到问题?
-
Issue is it only run grep once and is done不,这是不对的。 -
我不认为你会在这里遇到它,但是在使用 grep 的较长管道链中要小心(特别是多次使用),它可能会因块缓冲而失效,因此不会产生任何输出相当长一段时间,除非你明确指定 --line-buffered
-
啊链接是问题!这解决了它@ChrisStratton