tail 命令 – 查看文件尾部内容

tail 命令的功能是用于查看文件尾部内容,默认会在终端界面上显示出指定文件的末尾十行,如果指定了多个文件,则会在显示的每个文件内容前面加上文件名来加以区分。

目录

一、语法格式

二、常用参数

三、命令实战

3.1 默认显示指定文件最后10行

3.2 显示指定文件最后200个字节

3.3 显示指定文件第200个字节后所有内容

3.4 显示指定文件最后5行

3.5 显示指定文件第15行后的所有内容

3.6 显示指定多个文件并输出文件名

3.7 显示指定多个文件不输出文件名

3.8 高阶玩法,动态查看指定文件

一、语法格式

tail [参数] 文件名

二、常用参数

-c指定输出文件尾部的字符数
-n指定输出文件尾部的行数
-f持续输出文件尾部最新内容

三、命令实战

3.1 默认显示指定文件最后10行

 [root@linux1 ~]# tail /var/log/messages
 Apr 23 13:11:16 linux1 kernel: e1000: ens32 NIC Link is Up 1000 Mbps Full Duplex, Flow Control: None
 Apr 23 13:11:16 linux1 NetworkManager[783]: <info>  [1682226676.2885] device (ens32): carrier: link connected
 Apr 23 13:14:29 linux1 chronyd[803]: Selected source 119.28.183.184
 Apr 23 13:16:38 linux1 chronyd[803]: Selected source 202.118.1.81
 Apr 23 14:01:01 linux1 systemd: Started Session 5 of user root.
 Apr 23 15:01:01 linux1 systemd: Started Session 6 of user root.
 Apr 23 15:21:53 linux1 systemd-logind: New session 7 of user root.
 Apr 23 15:21:53 linux1 systemd: Started Session 7 of user root.
 Apr 23 15:22:34 linux1 systemd-logind: Removed session 1.
 Apr 23 16:01:01 linux1 systemd: Started Session 8 of user root.

3.2 显示指定文件最后200个字节

 [root@linux1 ~]# tail -c 200 /var/log/messages
 of user root.
 Apr 23 15:21:53 linux1 systemd: Started Session 7 of user root.
 Apr 23 15:22:34 linux1 systemd-logind: Removed session 1.
 Apr 23 16:01:01 linux1 systemd: Started Session 8 of user root.

3.3 显示指定文件第200个字节后所有内容

 [root@linux1 ~]# tail -c +200 /var/log/messages
 11:10 linux1 systemd: Time has been changed
 Apr 23 13:11:14 linux1 chronyd[803]: Forward time jump detected!
 Apr 23 13:11:14 linux1 chronyd[803]: Can't synchronise: no selectable sources
 Apr 23 13:11:16 linux1 kernel: e1000: ens32 NIC Link is Up 1000 Mbps Full Duplex, Flow Control: None
 Apr 23 13:11:16 linux1 NetworkManager[783]: <info>  [1682226676.2885] device (ens32): carrier: link connected
 Apr 23 13:14:29 linux1 chronyd[803]: Selected source 119.28.183.184
 Apr 23 13:16:38 linux1 chronyd[803]: Selected source 202.118.1.81
 Apr 23 14:01:01 linux1 systemd: Started Session 5 of user root.
 Apr 23 15:01:01 linux1 systemd: Started Session 6 of user root.
 Apr 23 15:21:53 linux1 systemd-logind: New session 7 of user root.
 Apr 23 15:21:53 linux1 systemd: Started Session 7 of user root.
 Apr 23 15:22:34 linux1 systemd-logind: Removed session 1.
 Apr 23 16:01:01 linux1 systemd: Started Session 8 of user root.

3.4 显示指定文件最后5行

 [root@linux1 ~]# tail -n 5 /var/log/messages
 Apr 23 15:01:01 linux1 systemd: Started Session 6 of user root.
 Apr 23 15:21:53 linux1 systemd-logind: New session 7 of user root.
 Apr 23 15:21:53 linux1 systemd: Started Session 7 of user root.
 Apr 23 15:22:34 linux1 systemd-logind: Removed session 1.
 Apr 23 16:01:01 linux1 systemd: Started Session 8 of user root.
 ​

3.5 显示指定文件第15行后的所有内容

 [root@linux1 ~]# tail -n +15 /var/log/messages
 Apr 23 15:22:34 linux1 systemd-logind: Removed session 1.
 Apr 23 16:01:01 linux1 systemd: Started Session 8 of user root.

3.6 显示指定多个文件并输出文件名

 [root@linux1 ~]# tail -v 1.txt 2.txt
 ==> 1.txt <==
 222
 1eufhdjf
 hello world 
 ​
 ==> 2.txt <==
 Hello world
 Hello world

3.7 显示指定多个文件不输出文件名

 [root@linux1 ~]# tail -q 1.txt 2.txt
 222
 1eufhdjf
 hello world 
 Hello world
 Hello world

3.8 高阶玩法,动态查看指定文件

默认输出指定文件最后十行,同时监视文件内容有无变化,如有新增继续输出到屏幕,直到 Ctrl+c 退出。

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值