tail:读取整个文件,然后跟随

Son*_*nny 62 tail

我想要一种tail -f读取整个文件然后在写入时继续遵循它的行为。


解决方案

根据我接受的答案,这是有效的: tail -f -n +1 {filename}

工作原理:-f选项继续“跟随”文件并在将新行写入文件时输出新行。该-n +1指示tail开始阅读从第一行的文件。使用-n -10将从文件的最后十行开始。

Tim*_*uck 75

tail -f -n +1
Run Code Online (Sandbox Code Playgroud)

使用man tail将为您提供更多详细信息,相关摘录如下。

<snip>Numbers having a leading plus (`+') sign are relative to the
beginning of the input, for example, ``-n +2'' starts the display at the
second line of the input.</snip>

-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.

-n number
        The location is number lines.
Run Code Online (Sandbox Code Playgroud)

  • 您能否将这些“更多详细信息”添加到您的答案中?请解释*为什么*和*如何*您的解决方案有效。(在低质量帖子队列中找到您的答案。) (3认同)
  • @waltinator 我并没有真正要求自己。我让他添加更多细节,因为他的帖子被标记为低质量,但我不想投票删除,因为他给出了正确的答案。 (3认同)