search
尋找貓咪~QQ 地點 桃園市桃園區 Taoyuan , Taoyuan

每天一個Linux指令- tail (從指定點開始將檔寫到標準輸出) – jashliao部落格

每天一個Linux指令- tail (從指定點開始將檔寫到標準輸出)

拷貝來源:

01.http://www.cnblogs.com/peida/archive/2012/12/05/2803591.html

02.http://www.cnblogs.com/peida/archive/2012/11/07/2758084.html

tail 命令從指定點開始將檔寫到標準輸出.使用tail命令的-f選項可以方便的查閱正在改變的日誌檔,tail -f filename會把filename裡最尾部的內容顯示在螢幕上,並且不但刷新,使你看到最新的檔內容. 

1命令格式;

tail[必要參數][選擇參數][檔]   

2命令功能:

用於顯示指定檔末尾內容,不指定檔時,作為輸入資訊進行處理。常用查看日誌檔

3命令參數:

-f 迴圈讀取

-q 不顯示處理資訊

-v 顯示詳細的處理資訊

-c<數目> 顯示的位元組數

-n<行數> 顯示行數

–pid=PID 與-f合用,表示在進程ID,PID死掉之後結束. 

-q, –quiet, –silent 從不輸出給出檔案名的首部 

-s, –sleep-interval=S 與-f合用,表示在每次反復的間隔休眠S秒 

4使用實例:

實例1:顯示檔末尾內容

命令:tail -n 5 log2014.log

輸出:

[root@localhost test]# tail -n 5 log2014.log 

2014-09

2014-10

2014-11

2014-12

==============================[root@localhost test]#

說明:

顯示檔最後5行內容

實例2:迴圈查看檔內容

命令:tail -f test.log

輸出:

[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 ~]#

說明:

ping 192.168.120.204 > test.log & //在後臺ping遠端主機。並輸出檔到test.log;這種做法也使用於一個以上的檔案監視。用Ctrl+c來終止。 

實例3:從第5行開始顯示檔

命令: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

==============================

 



熱門推薦

本文由 jashliaoeuwordpress 提供 原文連結

寵物協尋 相信 終究能找到回家的路
寫了7763篇文章,獲得2次喜歡
留言回覆
回覆
精彩推薦