每(mei)天一個linux命令(15):tail 命令
tail 命令從指定點開始將文(wen)(wen)(wen)件(jian)(jian)寫到標準輸出.使用tail命令的(de)(de)-f選(xuan)項可以方便(bian)的(de)(de)查閱(yue)正(zheng)在改變(bian)的(de)(de)日(ri)志文(wen)(wen)(wen)件(jian)(jian),tail -f filename會把filename里最尾(wei)部的(de)(de)內(nei)容顯示在屏幕(mu)上,并且不(bu)但刷新(xin),使你看到最新(xin)的(de)(de)文(wen)(wen)(wen)件(jian)(jian)內(nei)容.
1.命令格式;
tail[必要參數(shu)(shu)][選擇參數(shu)(shu)][文件]
2.命令功能:
用于(yu)顯示指定文件末尾內容,不指定文件時,作(zuo)為輸入(ru)信(xin)息(xi)進行處理(li)。常(chang)用查(cha)看日(ri)志文件。
3.命令參數(shu):
-f 循環讀取(qu)
-q 不顯示(shi)處理信(xin)息(xi)
-v 顯示詳細的處理信息
-c<數(shu)目> 顯(xian)示的字節數(shu)
-n<行(xing)數(shu)> 顯示行(xing)數(shu)
--pid=PID 與-f合(he)用(yong),表示在進(jin)程(cheng)ID,PID死(si)掉之后結束.
-q, --quiet, --silent 從不輸(shu)出給出文件名的(de)首部
-s, --sleep-interval=S 與-f合用,表示在每(mei)次(ci)反復的(de)間隔休眠S秒
4.使用實例:
實(shi)例1:顯示文件末尾內容
命(ming)令:
tail -n 5 log2014.log
輸出:
[root@localhost test]# tail -n 5 log2014.log
2014-09
2014-10
2014-11
2014-12
==============================[root@localhost test]#
說明(ming):
顯示文件最后5行(xing)內容
實例2:循環查看文件內(nei)容(rong)
命令(ling):
tail -f test.log
輸(shu)出:
[root@localhost ~]# ping 192.168.120.204 > test.log &
[1] 11891[root@localhost ~]# tail -f test.log
PING 192.168.120.204 (192.168.120.204) 56(84) bytes of data.
64 bytes from 192.168.120.204: icmp_seq=1 ttl=64 time=0.038 ms
64 bytes from 192.168.120.204: icmp_seq=2 ttl=64 time=0.036 ms
64 bytes from 192.168.120.204: icmp_seq=3 ttl=64 time=0.033 ms
64 bytes from 192.168.120.204: icmp_seq=4 ttl=64 time=0.027 ms
64 bytes from 192.168.120.204: icmp_seq=5 ttl=64 time=0.032 ms
64 bytes from 192.168.120.204: icmp_seq=6 ttl=64 time=0.026 ms
64 bytes from 192.168.120.204: icmp_seq=7 ttl=64 time=0.030 ms
64 bytes from 192.168.120.204: icmp_seq=8 ttl=64 time=0.029 ms
64 bytes from 192.168.120.204: icmp_seq=9 ttl=64 time=0.044 ms
64 bytes from 192.168.120.204: icmp_seq=10 ttl=64 time=0.033 ms
64 bytes from 192.168.120.204: icmp_seq=11 ttl=64 time=0.027 ms
[root@localhost ~]#
說(shuo)明(ming):
ping 192.168.120.204 > test.log & //在后臺ping遠程(cheng)主機(ji)。并輸(shu)出文件到(dao)test.log;這種做法也使用于一個以上的檔案監視。用Ctrl+c來終(zhong)止。
實例3:從第5行(xing)開(kai)始顯(xian)示文件
命令:
tail -n +5 log2014.log
輸出:
[root@localhost test]# cat log2014.log
2014-01
2014-02
2014-03
2014-04
2014-05
2014-06
2014-07
2014-08
2014-09
2014-10
2014-11
2014-12
==============================
[root@localhost test]# tail -n +5 log2014.log
2014-05
2014-06
2014-07
2014-08
2014-09
2014-10
2014-11
2014-12
==============================
關注 熵減黑客 ,一起學習成長
