linux命令之tail
linux命令tail用来查看文件的最后N行内容,默认tail查看最后10行内容
tail [参数] 文件
参数 | 说明 |
-n | 显示文件默认N行,默认显示10行,可以不写 |
-q | 隐藏文件名,在查看两个及以上文件名的情况下有效 |
-v | 显示文件名 |
-f | (循环读取)监视 filename 文件的尾部内容(默认 10 行,相当于增加参数-n 10)刷新显示在屏幕上,退出按下 ctrl+c |
命令:
tail -n 5 a.txt
- [root@centos79-3 ~]# tail -n 5 a.txt
- 8
- 9
- 10
- 11
- 12
- [root@centos79-3 ~]#
- [root@centos79-3 ~]# tail -q -n 5 a.txt b.txt
- 8
- 9
- 10
- 11
- 12
- 8
- 9
- 10
- 11
- 12
- [root@centos79-3 ~]#
命令:
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 ~]#
命令:
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...