将文件回显到标准输出吗?

将文件回显到标准输出吗?

我有一个将输出记录到 log.txt 的进程。如果我想实时查看进程的状态,有没有办法将该输出回显到 stdout,而不是在文本编辑器中打开日志并不断重新加载?

答案1

对于终端上一个非常简单的解决方案:

% tail -f log_file.log

从尾部主文件(即man 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.

 -F      The -F option implies the -f option, but tail will also check to see
         if the file being followed has been renamed or rotated.  The file is
         closed and reopened when tail detects that the filename being read
         from has a new inode number.  The -F option is ignored if reading
         from standard input rather than a file.

答案2

用于tail -f显示文件的末尾,并随着文件的增大而“跟随”它。

答案3

使用:

tail -f log.txt

或者换一种口味:

watch tail log.txt

相关内容