tail 命令从指定点开始将文件写到标准输出.使用tail命令的-f选项可以方便的查阅正在改变的日志文件,tail -f filename会把filename里最尾部的内容显示在屏幕上,并且不但刷新,使你看到最新的文件内容.
1.命令格式:
tail [OPTION]… [FILE]…
2.命令功能:
tail – output the last part of files,作为输入信息进行处理。常用查看日志文件。
3.命令参数:
-f,–follow[={name|descriptor}] 循环读取
-q 不显示处理信息
-v 显示详细的处理信息
-c<数目> 显示的字节数
-n,–lines=K 显示的行数, output the last K lines, instead of the last 10; or use -n +K to output lines starting with the Kth
–pid=PID 与-f合用,表示在进程ID,PID死掉之后结束.
-q, –quiet, –silent 从不输出给出文件名的首部
-s, –sleep-interval=S 与-f合用,表示在每次反复的间隔休眠S秒
4. 常用范例:
例1:循环输出内容,如果有日志输出到这个文件中,会直接显示在屏幕上面,方便调试等操作,这样有新的日志产生就可以直接看到
[root@localhost ~]#tail -f /var/log/messages Mar 13 20:55:56 bogon firmware.sh[37229]: Cannot find firmware file 'intel-ucode/06-4e-03' Mar 13 20:55:56 bogon kernel: Booting Node 0 Processor 2 APIC 0x4 Mar 13 20:55:56 bogon kernel: Disabled fast string operations 。。。。。。。
例2:指定输出内容的多少,默认是输出10行的数据
[root@localhost ~]#tail /var/log/messages #一共十行 Mar 13 20:55:56 bogon firmware.sh[37229]: Cannot find firmware file 'intel-ucode/06-4e-03' Mar 13 20:55:56 bogon kernel: Booting Node 0 Processor 2 APIC 0x4 Mar 13 20:55:56 bogon kernel: Disabled fast string operations Mar 13 20:55:56 bogon kernel: mce: CPU supports 0 MCE banks Mar 13 20:55:56 bogon kernel: Skipped synchronization checks as TSC is reliable. Mar 13 20:55:56 bogon kernel: Will online and init hotplugged CPU: 2 Mar 13 20:55:56 bogon kernel: microcode: CPU2 sig=0x406e3, pf=0x1, revision=0x9e Mar 13 20:55:56 bogon kernel: platform microcode: firmware: requesting intel-ucode/06-4e-03 Mar 13 20:55:56 bogon firmware.sh[37301]: Cannot find firmware file 'intel-ucode/06-4e-03' Mar 13 20:56:56 bogon kernel: hrtimer: interrupt took 4581731 ns [root@localhost ~]#tail -n 5 /var/log/messages Mar 13 20:55:56 bogon kernel: Will online and init hotplugged CPU: 2 Mar 13 20:55:56 bogon kernel: microcode: CPU2 sig=0x406e3, pf=0x1, revision=0x9e Mar 13 20:55:56 bogon kernel: platform microcode: firmware: requesting intel-ucode/06-4e-03 Mar 13 20:55:56 bogon firmware.sh[37301]: Cannot find firmware file 'intel-ucode/06-4e-03' Mar 13 20:56:56 bogon kernel: hrtimer: interrupt took 4581731 ns
例3:从多少行开始显示
[root@localhost ~]#cat test 1 2 3 4 5 6 7 8 9 [root@localhost ~]#tail -n 5 test 6 7 8 9 [root@localhost ~]#tail -n +5 test 5 6 7 8 9
好像最多的就是:tail -f或者tail -n选项
–
–
–
评论前必须登录!
注册