我想要一种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)