Linux命令之tail

tail [选项] [文件]

    tail命令与head命令相对,输出文件结尾部分,默认情况下显示文件的最后10行。如果指定多个文件,每个文件前都有一个标题,给出文件名。如果没有指定文件,或当文件为-时,读取标准输入。

(1).常用选项选项

-c,--bytes=[+]K 显示文件最后K个字节。如果K前有+,则表示显示除开头K字节外的所有内容

-f,--follw[={name|descriptor}] 随着文件的增大输出附加数据;缺少参数时表示描述符。多用于查看日志文件。

-n,--lines=[+]K 显示文件最后K行。如果K前有+,则表示显示除开头K行外所有行

-q,--quiet,--silent 不显示标题文件名

-v,--verbose 总是显示标题文件名

(2).实例

指定行数或字节数

[root@xuexi ~]# tail -n 2 /etc/passwd
xf:x:1000:1000:xf:/home/xf:/bin/bash
saned:x:989:983:SANE scanner daemon user:/usr/share/sane:/sbin/nologin
[root@xuexi ~]# tail -c 10 /etc/passwd
n/nologin

指定开头除N行或N字节不显示外,全部显示

[root@xuexi ~]# tail -n +40 /etc/passwd
ntp:x:38:38::/etc/ntp:/sbin/nologin
tcpdump:x:72:72::/:/sbin/nologin
xf:x:1000:1000:xf:/home/xf:/bin/bash
saned:x:989:983:SANE scanner daemon user:/usr/share/sane:/sbin/nologin
[root@xuexi ~]# tail -c +2048 /etc/passwd
/var/spool/postfix:/sbin/nologin
ntp:x:38:38::/etc/ntp:/sbin/nologin
tcpdump:x:72:72::/:/sbin/nologin
xf:x:1000:1000:xf:/home/xf:/bin/bash
saned:x:989:983:SANE scanner daemon user:/usr/share/sane:/sbin/nologin

总是显示标题文件名

[root@xuexi ~]# tail -n 2 -v /etc/passwd
==> /etc/passwd <==
xf:x:1000:1000:xf:/home/xf:/bin/bash
saned:x:989:983:SANE scanner daemon user:/usr/share/sane:/sbin/nologin

指定多个文件

[root@xuexi ~]# tail -n 2 /etc/passwd /etc/firewalld/firewalld.conf
==> /etc/passwd <==
xf:x:1000:1000:xf:/home/xf:/bin/bash
saned:x:989:983:SANE scanner daemon user:/usr/share/sane:/sbin/nologin
        //两个文件之间会空一行
==> /etc/firewalld/firewalld.conf <==
# Default: system
AutomaticHelpers=system

不显示标题文件名

[root@xuexi ~]# tail -n 2 -q /etc/passwd /etc/firewalld/firewalld.conf
xf:x:1000:1000:xf:/home/xf:/bin/bash
saned:x:989:983:SANE scanner daemon user:/usr/share/sane:/sbin/nologin      //此时中间就没有空行
# Default: system
AutomaticHelpers=system

 

转载于:https://www.cnblogs.com/diantong/p/10370517.html

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值