将脚本日志文件连续显示到屏幕上

时间:2021-12-30 13:57:06

I am creating an application that writes to a log file, and I need to know how in Linux / Bash to continuously display the log file to the screen (updating the screen with every new line put into the log).

我正在创建一个向日志文件写入的应用程序,我需要知道如何在Linux / Bash中不断地将日志文件显示到屏幕上(在日志中插入每一行时更新屏幕)。

So as an example, lets say I want to push a running log of apache/error.log to the screen (ssh terminal) continuously updating.

举个例子,假设我想推一个apache/error的运行日志。登录到屏幕(ssh终端),不断更新。

5 个解决方案

#1


85  

Try the tail command:

试着尾巴命令:

tail -f filename

#2


21  

Another solution is

另一个解决方案是

 less +F filename

or just less filename and typing "F" into it (pressing shift+f). It can be better than tail, because it allows you to cancel continuous printing temporary, go backward to look something and reenable it with "F" (shift+f) again

或者只输入更少的文件名并输入“F”(按shift+ F)。它可能比tail要好,因为它允许您暂时取消连续打印,向后查找并重新启用它,并再次使用F (shift+ F)

#3


9  

The watch command can also be of use.

watch命令也可以使用。

watch tail logfile

Would show you the last 5 lines of the log file. It can be extended to any command which prints stuff to stdout.

将显示日志文件的最后5行。它可以扩展到任何输出到stdout的命令。

Yes, using tail -f is the traditional solution, but depending on what you are trying to do, this might work better.

是的,使用tail -f是传统的解决方案,但这取决于您要做什么,这可能会更好。

#4


6  

You can also:

您还可以:

less filename.txt
and press 'F'

has one plus - you can anytime CTRL-C and scroll back in log and start watching again with the 'F'.

有一个加号-你可以随时按下CTRL-C并回滚到日志中,然后用“F”开始再次观看。

#5


5  

ssh {remotehost} tail -n0f {logfile}

ssh {remotehost}尾-n0f {logfile}

This will give you zero lines initially, and continuously print any new lines that appear in the file.

这将使您最初得到零行,并连续地打印文件中出现的任何新行。

#1


85  

Try the tail command:

试着尾巴命令:

tail -f filename

#2


21  

Another solution is

另一个解决方案是

 less +F filename

or just less filename and typing "F" into it (pressing shift+f). It can be better than tail, because it allows you to cancel continuous printing temporary, go backward to look something and reenable it with "F" (shift+f) again

或者只输入更少的文件名并输入“F”(按shift+ F)。它可能比tail要好,因为它允许您暂时取消连续打印,向后查找并重新启用它,并再次使用F (shift+ F)

#3


9  

The watch command can also be of use.

watch命令也可以使用。

watch tail logfile

Would show you the last 5 lines of the log file. It can be extended to any command which prints stuff to stdout.

将显示日志文件的最后5行。它可以扩展到任何输出到stdout的命令。

Yes, using tail -f is the traditional solution, but depending on what you are trying to do, this might work better.

是的,使用tail -f是传统的解决方案,但这取决于您要做什么,这可能会更好。

#4


6  

You can also:

您还可以:

less filename.txt
and press 'F'

has one plus - you can anytime CTRL-C and scroll back in log and start watching again with the 'F'.

有一个加号-你可以随时按下CTRL-C并回滚到日志中,然后用“F”开始再次观看。

#5


5  

ssh {remotehost} tail -n0f {logfile}

ssh {remotehost}尾-n0f {logfile}

This will give you zero lines initially, and continuously print any new lines that appear in the file.

这将使您最初得到零行,并连续地打印文件中出现的任何新行。