Shell,监视文件内容

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的手册页。 它说命令显示文件的最后一部分

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

翻译自: https://flaviocopes.com/tail/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值