tail--命令详解

tail:显示文件内容尾部

功能说明:用于显示文件内容的尾部,默认输出文件的最后10行。

语法格式: tail 【option】 【file】

                  tail     选项         文件

参数: -n  指定显示的行数

[root@template ~ 15:08:16]]# tail /etc/passwd  #不加-n默认输出末尾10行
abrt:x:173:173::/etc/abrt:/sbin/nologin
sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin
postfix:x:89:89::/var/spool/postfix:/sbin/nologin
rpc:x:32:32:Rpcbind Daemon:/var/lib/rpcbind:/sbin/nologin
rpcuser:x:29:29:RPC Service User:/var/lib/nfs:/sbin/nologin
nfsnobody:x:65534:65534:Anonymous NFS User:/var/lib/nfs:/sbin/nologin
ntp:x:38:38::/etc/ntp:/sbin/nologin
nginx:x:111:1000::/home/nginx:/sbin/nologin
openvpn:x:998:996:OpenVPN:/etc/openvpn:/sbin/nologin
redis:x:2000:2000::/home/redis:/sbin/nologin

[root@template ~ 15:08:52]]# tail -n 5 /etc/passwd       #第二种写法可以写成 tail -5 /etc/passwd
nfsnobody:x:65534:65534:Anonymous NFS User:/var/lib/nfs:/sbin/nologin
ntp:x:38:38::/etc/ntp:/sbin/nologin
nginx:x:111:1000::/home/nginx:/sbin/nologin
openvpn:x:998:996:OpenVPN:/etc/openvpn:/sbin/nologin
redis:x:2000:2000::/home/redis:/sbin/nologin

参数:-f   实时输出文件变化后追加的数据

[root@template ~ 15:11:57]]# tail -f /opt/redis_6380/logs/redis_6380.log  #实时监控redis的日志文件的变化
1821:M 28 Feb 2021 23:22:42.466 * FAIL message received from dfeaed753633b76bc38f2dcc28143e18db256357 about 7f0af1b25784d2d8a8eed8cce54df1e5b8720590
1821:M 28 Feb 2021 23:22:42.466 * FAIL message received from dfeaed753633b76bc38f2dcc28143e18db256357 about 420b366762033aa92bdce76ccf30a7bb0acc6e33
1821:M 28 Feb 2021 23:22:42.873 # Failover auth granted to 13c20233f64261bac6d1f412418de98eb8d91f5e for epoch 12
1821:M 28 Feb 2021 23:23:43.775 # Failover auth granted to 13c20233f64261bac6d1f412418de98eb8d91f5e for epoch 13
1821:M 28 Feb 2021 23:24:44.769 # Failover auth granted to 13c20233f64261bac6d1f412418de98eb8d91f5e for epoch 14
1821:M 01 Mar 2021 00:22:27.609 * Replication backlog freed after 3600 seconds without connected replicas.
1821:M 01 Mar 2021 08:39:17.048 # User requested shutdown...
1821:M 01 Mar 2021 08:39:17.048 * Calling fsync() on the AOF file.
1821:M 01 Mar 2021 08:39:17.048 * Removing the pid file.
1821:M 01 Mar 2021 08:39:17.048 # Redis is now ready to exit, bye bye...

参数:-F 实时输出文件变化后追加的数据,不会因为文件不存在了就自动退出

[root@template ~ 15:14:37]]# tail -F /opt/redis_6380/logs/redis_6380.log   #当文件不存在时会返回报错,不会退出一直等待文件生成。
1821:M 28 Feb 2021 23:22:42.466 * FAIL message received from dfeaed753633b76bc38f2dcc28143e18db256357 about 7f0af1b25784d2d8a8eed8cce54df1e5b8720590
1821:M 28 Feb 2021 23:22:42.466 * FAIL message received from dfeaed753633b76bc38f2dcc28143e18db256357 about 420b366762033aa92bdce76ccf30a7bb0acc6e33
1821:M 28 Feb 2021 23:22:42.873 # Failover auth granted to 13c20233f64261bac6d1f412418de98eb8d91f5e for epoch 12
1821:M 28 Feb 2021 23:23:43.775 # Failover auth granted to 13c20233f64261bac6d1f412418de98eb8d91f5e for epoch 13
1821:M 28 Feb 2021 23:24:44.769 # Failover auth granted to 13c20233f64261bac6d1f412418de98eb8d91f5e for epoch 14
1821:M 01 Mar 2021 00:22:27.609 * Replication backlog freed after 3600 seconds without connected replicas.
1821:M 01 Mar 2021 08:39:17.048 # User requested shutdown...

 补充备注:tailf==tail -f 

posted on 2021-03-01 15:16  弓长三寿  阅读(993)  评论(0编辑  收藏  举报