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

阅读: 评论:0

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

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/messagesApr 23 13:11:16 linux1 kernel: e1000: ens32 NIC Link is Up 1000 Mbps Full Duplex, Flow Control: NoneApr 23 13:11:16 linux1 NetworkManager[783]: <info>  [1682226676.2885] device (ens32): carrier: link connectedApr 23 13:14:29 linux1 chronyd[803]: Selected source 119.28.183.184Apr 23 13:16:38 linux1 chronyd[803]: Selected source 202.118.1.81Apr 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/messagesof 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/messages11:10 linux1 systemd: Time has been changedApr 23 13:11:14 linux1 chronyd[803]: Forward time jump detected!Apr 23 13:11:14 linux1 chronyd[803]: Can't synchronise: no selectable sourcesApr 23 13:11:16 linux1 kernel: e1000: ens32 NIC Link is Up 1000 Mbps Full Duplex, Flow Control: NoneApr 23 13:11:16 linux1 NetworkManager[783]: <info>  [1682226676.2885] device (ens32): carrier: link connectedApr 23 13:14:29 linux1 chronyd[803]: Selected source 119.28.183.184Apr 23 13:16:38 linux1 chronyd[803]: Selected source 202.118.1.81Apr 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/messagesApr 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/messagesApr 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 - 2.txt==> 1.txt <==2221eufhdjfhello world ​==> 2.txt <==Hello worldHello world

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

 [root@linux1 ~]# tail - 2.txt2221eufhdjfhello world Hello worldHello world

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

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

本文发布于:2024-02-05 04:31:26,感谢您对本站的认可!

本文链接:https://www.4u4v.net/it/170724212063058.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:尾部   命令   文件   内容   tail
留言与评论(共有 0 条评论)
   
验证码:

Copyright ©2019-2022 Comsenz Inc.Powered by ©

网站地图1 网站地图2 网站地图3 网站地图4 网站地图5 网站地图6 网站地图7 网站地图8 网站地图9 网站地图10 网站地图11 网站地图12 网站地图13 网站地图14 网站地图15 网站地图16 网站地图17 网站地图18 网站地图19 网站地图20 网站地图21 网站地图22/a> 网站地图23