Linux的 tail 命令详解

20 篇文章 1 订阅
# tail --help
用法:tail [选项]... [文件]...
显示每个指定文件的最后10 行到标准输出。
若指定了多于一个文件,程序会在每段输出的开始添加相应文件名作为头。
如果不指定文件或文件为"-" ,则从标准输入读取数据。

长选项必须使用的参数对于短选项时也是必需使用的。
  -c, --bytes=K         输出最后K 字节;另外,使用-c +K 从每个文件的
                        第K 字节输出
  -f, --follow[={name|descriptor}]
                即时输出文件变化后追加的数据。
                        -f, --follow 等于--follow=descriptor 
  -F            即--follow=name --retry
  -n, --lines=K            output the last K lines, instead of the last 10;
                           or use -n +K to output lines starting with the Kth
      --max-unchanged-stats=N
                           with --follow=name, reopen a FILE which has not
                           changed size after N (default 5) iterations
                           to see if it has been unlinked or renamed
                           (this is the usual case of rotated log files).
                           With inotify, this option is rarely useful.
      --pid=PID         同 -f 一起使用,当 PID 所对应的进程死去后终止
  -q, --quiet, --silent 不输出给出文件名的头
      --retry           即使目标文件不可访问依然试图打开;在与参数
                        --follow=name 同时使用时常常有用。
  -s, --sleep-interval=N   with -f, sleep for approximately N seconds
                             (default 1.0) between iterations.
                           With inotify and --pid=P, check process P at
                           least once every N seconds.
  -v, --verbose            always output headers giving file names
      --help            显示此帮助信息并退出
      --version         显示版本信息并退出

如果字节数或行数K 的第一个字符是"+",输出从文件开始第K 个项目,否则输出文件
最后K 个项目。K 可以使用一下几种单位之一:
b 512,kB 1000,K 1024,MB 1000*1000,M 1024*1024,
GB 1000*1000*1000,G 1024*1024*1024,以及T,P,E,Z,Y。
示例
//原始素材文件
# cat t.txt 
Apple
Banana
Cherry
Durian
Fig
Grape
Haw
Jujube
Kumquat
Lemon
Mango
Orange
Peach
//默认显示最后10行
# tail t.txt 
Durian
Fig
Grape
Haw
Jujube
Kumquat
Lemon
Mango
Orange
Peach
//只显示最后2行
# tail -n2 t.txt 
Orange
Peach
//从第10行开始显示
# tail -n+10 t.txt 
Lemon
Mango
Orange
Peach
//只显示最后7个字节(含回车换行)
# tail -c7 t.txt 
Peach



  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值