开发者

continuously print the last line of a file Linux termin

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.

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

So what i did for number 4 was:

cat /dev/null > emptyfile

This created开发者_Python百科 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.


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.

Example:

tail -f emptyfile

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


doesn't tail -f FILE_NAME help?


tail with watch or a loop with a delay.

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

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜