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