tail 命令从指定点开始将文件写到标准输出。使用tail
命令的-f
选项可以方便的查阅正在改变的日志文件,tail -f filename
会把filename
里最尾部的内容显示在屏幕上,并且不但刷新,以便看到最新的文件内容。
tail[必要参数][选择参数][文件]
用于显示指定文件末尾内容,不指定文件时,作为输入信息进行处理。常用查看日志文件。
-f
循环读取-q
不显示处理信息-v
显示详细的处理信息-c
<数目> 显示的字节数-n
<行数> 显示行数--pid=PID
与-f
合用,表示在进程ID
,PID
死掉之后结束。-q
, --quiet
, --silent
从不输出给出文件名的首部。-s
, --sleep-interval=S
与-f
合用,表示在每次反复的间隔休眠S秒 命令:
tail -n 5 log.log
演示执行及输出:
[zyiz@localhost test]$ tail -n 5 log.log this is line 20. this is line 21. this is line 22. -----------------end [zyiz@localhost test]$
说明:显示文件最后5行内容
命令:
tail -f ping.log
演示执行及输出:
[zyiz@localhost test]$ ping www.baidu.com > ping.log & [1] 2382 [zyiz@localhost test]$ tail -f ping.log bytes from 14.215.177.38 (14.215.177.38): icmp_seq=9 ttl=57 time=13.1 ms bytes from 14.215.177.38 (14.215.177.38): icmp_seq=10 ttl=57 time=14.7 ms bytes from 14.215.177.38 (14.215.177.38): icmp_seq=11 ttl=57 time=13.0 ms bytes from 14.215.177.38 (14.215.177.38): icmp_seq=12 ttl=57 time=16.0 ms bytes from 14.215.177.38 (14.215.177.38): icmp_seq=13 ttl=57 time=12.9 ms bytes from 14.215.177.38 (14.215.177.38): icmp_seq=14 ttl=57 time=14.5 ms bytes from 14.215.177.38 (14.215.177.38): icmp_seq=15 ttl=57 time=13.2 ms bytes from 14.215.177.38 (14.215.177.38): icmp_seq=16 ttl=57 time=13.3 ms bytes from 14.215.177.38 (14.215.177.38): icmp_seq=17 ttl=57 time=12.9 ms bytes from 14.215.177.38 (14.215.177.38): icmp_seq=18 ttl=57 time=13.2 ms bytes from 14.215.177.38 (14.215.177.38): icmp_seq=19 ttl=57 time=12.8 ms bytes from 14.215.177.38 (14.215.177.38): icmp_seq=20 ttl=57 time=12.4 ms bytes from 14.215.177.38 (14.215.177.38): icmp_seq=21 ttl=57 time=11.7 ms bytes from 14.215.177.38 (14.215.177.38): icmp_seq=22 ttl=57 time=13.1 ms bytes from 14.215.177.38 (14.215.177.38): icmp_seq=23 ttl=57 time=12.5 ms ^C [zyiz@localhost test]$
说明:
ping www.baidu.com > ping.log &
,在后台ping远程主机。并输出文件到ping.log
;这种做法也使用于一个以上的档案监视。用Ctrl+c
来终止。
命令:
tail -n +10 log.log
演示执行及输出:
[zyiz@localhost test]$ tail -n +10 log.log this is line 8. this is line 9. this is line 10. this is line 11. this is line 12. this is line 13. this is line 14. this is line 15. this is line 16. this is line 17. this is line 18. this is line 19. this is line 20. this is line 21. this is line 22. -----------------end [zyiz@localhost test]$