tail


命令说明:

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秒


命令实例:

实例1:显示文件末尾5行内容

 

命令:

#tail -n 5 1.log

 

[root@ilinux test]# cat 1.log
dd
sdf
fgh
ijk
ou
opkl
pokjwq
qwedc
fassdfe
kjk
[root@ilinux test]# tail -n 5 1.log
opkl
pokjwq
qwedc
fassdfe
kjk


实例2:循环查看文件内容

 

命令:

#tail -f 1.log

 

[root@ilinux test]# ping g.cn > 1.log
[root@ilinux test]# tail -f 1.log
PING g.cn (74.125.28.160) 56(84) bytes ofdata.
64 bytes from pc-in-f160.1e100.net(74.125.28.160): icmp_seq=1 ttl=128 time=242 ms
64 bytes from pc-in-f160.1e100.net(74.125.28.160): icmp_seq=2 ttl=128 time=241 ms
64 bytes from pc-in-f160.1e100.net(74.125.28.160): icmp_seq=3 ttl=128 time=241 ms
64 bytes from pc-in-f160.1e100.net(74.125.28.160): icmp_seq=4 ttl=128 time=244 ms
64 bytes from pc-in-f160.1e100.net(74.125.28.160): icmp_seq=5 ttl=128 time=244 ms
64 bytes from pc-in-f160.1e100.net(74.125.28.160): icmp_seq=6 ttl=128 time=240 ms
64 bytes from pc-in-f160.1e100.net(74.125.28.160): icmp_seq=7 ttl=128 time=248 ms
64 bytes from pc-in-f160.1e100.net(74.125.28.160): icmp_seq=8 ttl=128 time=245 ms
64 bytes from pc-in-f160.1e100.net(74.125.28.160): icmp_seq=9 ttl=128 time=240 ms


 实例3:从第5行开始显示文件

 

命令:

#tail -n +5 1.log

 

[root@ilinux test]# cat 1.log
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
[root@ilinux test]# tail -n +5 1.log
2005
2006
2007
2008
2009
2010