linux系列(十五):tail命令

一、命令格式:ui

  tail[必要參數][選擇參數][文件]  
spa

二、命令功能:日誌

 

  用於顯示指定文件末尾內容,不指定文件時,做爲輸入信息進行處理。經常使用查看日誌文件。code

三、命令參數:blog

-f 循環讀取
-q 不顯示處理信息
-v 顯示詳細的處理信息
-c<數目> 顯示的字節數
-n<行數> 顯示行數
--pid=PID 與-f合用,表示在進程ID,PID死掉以後結束. 
-q, --quiet, --silent 從不輸出給出文件名的首部 
-s, --sleep-interval=S 與-f合用,表示在每次反覆的間隔休眠S秒 

四、經常使用實例進程

(1)、顯示文件尾部內容ip

命令:it

  tail -n 5 a.txtio

輸出:class

felix@felix-computer:~/test$ cat a.txt 
第0行
第1行
第2行
第3行
第4行
第5行
第6行
第7行
第8行
第9行
felix@felix-computer:~/test$ tail -n 5 a.txt 
第5行
第6行
第7行
第8行
第9行
felix@felix-computer:~/test$ 

(2)、循環查看文件內容

命令:

    tail -f a.log

輸出:

felix@felix-computer:~/test$ ping baidu.com > a.log &
[1] 4581
felix@felix-computer:~/test$ tail -f a.log 
PING baidu.com (123.125.115.110) 56(84) bytes of data.
64 bytes from 123.125.115.110 (123.125.115.110): icmp_seq=1 ttl=50 time=6.38 ms
64 bytes from 123.125.115.110 (123.125.115.110): icmp_seq=2 ttl=50 time=6.33 ms
64 bytes from 123.125.115.110 (123.125.115.110): icmp_seq=3 ttl=50 time=6.04 ms
64 bytes from 123.125.115.110 (123.125.115.110): icmp_seq=4 ttl=50 time=9.79 ms
64 bytes from 123.125.115.110 (123.125.115.110): icmp_seq=5 ttl=50 time=6.10 ms
64 bytes from 123.125.115.110 (123.125.115.110): icmp_seq=6 ttl=50 time=11.3 ms

(3)、從第六行開始顯示內容

命令:

    tail -n +6 a.txt

輸出:(注意和不加+的區別)

felix@felix-computer:~/test$ cat a.txt 
第0行
第1行
第2行
第3行
第4行
第5行
第6行
第7行
第8行
第9行
felix@felix-computer:~/test$ tail -n +6 a.txt 
第5行
第6行
第7行
第8行
第9行
felix@felix-computer:~/test$
相關文章
相關標籤/搜索