Linux命令(94)之tail

linux命令之tail

1.tail介绍

linux命令tail用来查看文件的最后N行内容,默认tail查看最后10行内容

2.tail用法

tail 参数 文件

|----|---------------------------------------------------------------------|
| 参数 | 说明 |
| -n | 显示文件默认N行,默认显示10行,可以不写 |
| -q | 隐藏文件名,在查看两个及以上文件名的情况下有效 |
| -v | 显示文件名 |
| -f | (循环读取)监视 filename 文件的尾部内容(默认 10 行,相当于增加参数-n 10)刷新显示在屏幕上,退出按下 ctrl+c |
[tail常用参数]

3.实例

3.1.显示文件的最后5行内容

命令:

tail -n 5 a.txt

复制代码
[root@centos79-3 ~]# tail -n 5 a.txt
8
9
10
11
12
[root@centos79-3 ~]# 

3.2.显示a.txt/b.txt文件的最后5行内容

复制代码
[root@centos79-3 ~]# tail -q -n 5 a.txt b.txt
8
9
10
11
12
8
9
10
11
12
[root@centos79-3 ~]# 

3.3.显示a.txt/b.txt文件的最后5行内容,并显示分开文件名

命令:

tail -v -n 5 a.txt b.txt

复制代码
[root@centos79-3 ~]# tail -v -n 5 a.txt b.txt
==> a.txt <==
8
9
10
11
12

==> b.txt <==
8
9
10
11
12
[root@centos79-3 ~]# 

3.4.实时读取/var/log/messages文件内容

命令:

tail -f /var/log/messages

复制代码
[root@centos79-3 ~]# tail -f /var/log/messages
Sep 19 10:05:19 centos79-3 NetworkManager[710]: <info>  [1695089119.0694] dhcp4 (ens32):   nameserver '192.168.10.2'
Sep 19 10:05:19 centos79-3 NetworkManager[710]: <info>  [1695089119.0694] dhcp4 (ens32):   domain name 'localdomain'
Sep 19 10:05:19 centos79-3 NetworkManager[710]: <info>  [1695089119.0694] dhcp4 (ens32): state changed bound -> bound
Sep 19 10:05:19 centos79-3 dbus[708]: [system] Activating via systemd: service name='org.freedesktop.nm_dispatcher' unit='dbus-org.freedesktop.nm-dispatcher.service'
Sep 19 10:05:19 centos79-3 systemd: Starting Network Manager Script Dispatcher Service...
Sep 19 10:05:19 centos79-3 dhclient[806]: bound to 192.168.10.225 -- renewal in 855 seconds.
Sep 19 10:05:19 centos79-3 dbus[708]: [system] Successfully activated service 'org.freedesktop.nm_dispatcher'
Sep 19 10:05:19 centos79-3 systemd: Started Network Manager Script Dispatcher Service.
Sep 19 10:05:19 centos79-3 nm-dispatcher: req:1 'dhcp4-change' [ens32]: new request (2 scripts)
Sep 19 10:05:19 centos79-3 nm-dispatcher: req:1 'dhcp4-change' [ens32]: start running ordered scripts...
相关推荐
阿里云大数据AI技术9 小时前
阿里云 EMR AI 助手正式发布:从问答工具到全栈智能运维助手
运维·人工智能
你好潘先生15 小时前
别再记命令了,用 yeero do 说句人话就能跑脚本,而且不烧 token
服务器·python·命令行
orion571 天前
Missing Semester Class1:course overview and introduction of shell
linux
SkyWalking中文站1 天前
认识 Horizon UI · 6/17:Trace 探索器
运维·监控·自动化运维
用户120487221611 天前
Linux驱动编译与加载
linux·嵌入式
程序员老赵1 天前
服务器文件不想 SFTP 上传?Docker 跑个 File Browser,浏览器就能管理
服务器·docker·开源
火车叼位1 天前
写给初级开发者:SSL、SSH、HTTPS 与证书体系全解析
运维
vivo互联网技术2 天前
从 10 分钟到 1 秒:ES 深度分页任意跳页的三轮优化实战
服务器·数据库·redis·elasticsearch·深度分页
用户805533698032 天前
Input 子系统架构:Core、Handler、Driver 三层是怎么协作的
linux·嵌入式