One very useful command line tool I use is tail
. It’s a little Unix utility command that is found on almost any *nix system, including macOS and of course Linux.
我使用的一种非常有用的命令行工具是tail
。 这是一个小的Unix实用程序命令,几乎可以在所有* nix系统上找到,包括macOS以及Linux。
Here’s the man page for tail
. It says the command displays the last part of a file.
这是tail
的手册页。 它说命令显示文件的最后一部分 。
![](https://flaviocopes.com/tail/Screen%20Shot%202019-01-14%20at%2021.36.21.png)
The command can be used to display the last x lines of a file by using it with the -n
option. For example this command shows the last 2 lines of the file specified:
通过与-n
选项一起使用,该命令可用于显示文件的最后x行。 例如,此命令显示指定文件的最后两行:
tail -n 2 <filename>
tail -n 2 <filename>
I almost never used tail
like this though. What I used it the most was to “watch” a file for new content appended to it, by using the -f
option:
我几乎从来没有用过像这样的tail
。 我最常使用的是使用-f
选项“监视”文件中附加的新内容:
tail -f <filename>
tail -f <filename>
This starts the command and it just waits until there’s something new appended to the file.
这将启动命令,并且仅等待直到文件中附加了新内容。
For example I have a script that stays active for a while and fetches remote data, then prints some results to a text file. I just watch the results.txt
file for incoming data using
例如,我有一个脚本,该脚本将保持活动状态一段时间,并获取远程数据,然后将一些结果打印到文本文件中。 我只是看着使用输入数据的results.txt
文件
tail -f results.txt
tail -f results.txt