连续打印文件Linux termin的最后一行

时间:2021-08-05 16:59:27

Two questions, but only stuck on one. Feel that I need the first one so someone can help me make sense of it.

两个问题,但只有一个问题。感觉我需要第一个,这样有人可以帮助我理解它。

4) Use cat and /dev/null to create an empty file.

4)使用cat和/dev/null创建一个空文件。

5) Start a background process that continuously prints the last line of the file created in #4..

5)启动后台进程,连续打印第4条中创建的文件的最后一行。

So what i did for number 4 was:

我在第4题中所做的是:

cat /dev/null > emptyfile

This created an empty file. Okay so I am happy with that. The next question however confuses me. How can I read the last line of an empty file? Better yet how do I continuously do this? Running it in the background isn't a problem. Anyone have any ideas? We haven't covered scripting yet so I don't think that plays a role. As always, thanks for the help.

这创建了一个空文件。我对此很满意。下一个问题让我困惑。如何读取空文件的最后一行?更好的是,我如何持续地做到这一点?在后台运行它不是问题。谁有什么好主意吗?我们还没有涉及到脚本,所以我不认为它起作用。一如既往,谢谢你的帮助。

3 个解决方案

#1


21  

Use the UNIX command "tail" with the -f option. That will continuously print out contents from the file to the terminal as it is added to the file.

使用UNIX命令“tail”和-f选项。当文件被添加到文件中时,将不断地从文件打印到终端。

Example:

例子:

tail -f emptyfile

You can terminate the tail process by typing Ctrl + C.

您可以通过键入Ctrl + C终止尾部进程。

#2


3  

doesn't tail -f FILE_NAME help?

“tail -f FILE_NAME”是否有帮助?

#3


1  

tail with watch or a loop with a delay.

有手表的尾巴或有延迟的环。

Also, neither cat nor /dev/null are required.

而且,既不需要cat,也不需要/dev/null。

> emptyfile

tail and watch example:

尾巴和手表的例子:

watch tail -n 1 log.txt will always show the last line of the log file. Default interval in watch is 2 seconds.

观察尾部-n 1 log。txt将始终显示日志文件的最后一行。手表的默认间隔是2秒。

#1


21  

Use the UNIX command "tail" with the -f option. That will continuously print out contents from the file to the terminal as it is added to the file.

使用UNIX命令“tail”和-f选项。当文件被添加到文件中时,将不断地从文件打印到终端。

Example:

例子:

tail -f emptyfile

You can terminate the tail process by typing Ctrl + C.

您可以通过键入Ctrl + C终止尾部进程。

#2


3  

doesn't tail -f FILE_NAME help?

“tail -f FILE_NAME”是否有帮助?

#3


1  

tail with watch or a loop with a delay.

有手表的尾巴或有延迟的环。

Also, neither cat nor /dev/null are required.

而且,既不需要cat,也不需要/dev/null。

> emptyfile

tail and watch example:

尾巴和手表的例子:

watch tail -n 1 log.txt will always show the last line of the log file. Default interval in watch is 2 seconds.

观察尾部-n 1 log。txt将始终显示日志文件的最后一行。手表的默认间隔是2秒。