天天看點

每天進步一點點——linux——tail一            簡介二            指令格式三            常用參數四            所有參數五            示例二            參考資料

一            簡介

tail指令是從檔案末尾輸出檔案,這個指令常用于看日志。

二            指令格式

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

三            常用參數

  -f,--follow[={name|descriptor}]

                即時輸出檔案變化後追加的資料。

  -n  <行數>          顯示指定行數

四            所有參數

-c, --bytes=K        顯示指定的位元組數

  -f,--follow[={name|descriptor}]

                即時輸出檔案變化後追加的資料。

                        -f, --follow 等于--follow=descriptor

 -F            即--follow=name--retry

  -n,--lines=K           顯示指定的行數

     --max-unchanged-stats=N

                           with --follow=name,reopen a FILE which has not

                           changed size after N(default 5) iterations

                           to see if it hasbeen unlinked or renamed

                           (this is the usualcase of rotated log files).

                           With inotify, thisoption is rarely useful.

     --pid=PID         同 -f 一起使用,當 PID 所對應的程序死去後終止

  -q,--quiet, --silent 不輸出給出檔案名的頭

     --retry           即使目标檔案不可通路依然試圖打開;在與參數

                        --follow=name 同時使用時常常有用。

  -s,--sleep-interval=N   with -f, sleep forapproximately N seconds

                             (default 1.0)between iterations.

                           With inotify and--pid=P, check process P at

                           least once every Nseconds.

  -v,--verbose            always outputheaders giving file names

     --help            顯示此幫助資訊并退出

     --version         顯示版本資訊并退出

五            示例

5.1  顯示檔案後3行

[[email protected]~]# tail -n 3 install.log

安裝 words-3.0-17.el6.noarch

安裝 redhat-indexhtml-6-1.el6.noarch

*** FINISHED INSTALLING PACKAGES***[[email protected] ~]#

5.2  顯示檔案最後100個位元組

[[email protected]~]# tail -c 100 install.log

 words-3.0-17.el6.noarch

安裝 redhat-indexhtml-6-1.el6.noarch

*** FINISHED INSTALLING PACKAGES***[[email protected] ~]# 

5.1  動态顯示檔案

[[email protected]~]# ping 11.10.111.254 >aaa.log &

[1] 10653

[[email protected]~]# tail -f aaa.

aaa.log aaa.txt 

[[email protected]~]# tail -f aaa.log

PING 11.10.111.254 (11.10.111.254) 56(84)bytes of data.

64 bytes from 11.10.111.254: icmp_seq=1ttl=255 time=1.27 ms

64 bytes from 11.10.111.254: icmp_seq=2ttl=255 time=1.29 ms

64 bytes from 11.10.111.254: icmp_seq=3ttl=255 time=1.99 ms

64 bytes from 11.10.111.254: icmp_seq=4 ttl=255time=1.67 ms

64 bytes from 11.10.111.254: icmp_seq=5ttl=255 time=1.94 ms

64 bytes from 11.10.111.254: icmp_seq=6ttl=255 time=1.67 ms

64 bytes from 11.10.111.254: icmp_seq=7ttl=255 time=2.58 ms

64 bytes from 11.10.111.254: icmp_seq=8ttl=255 time=1.14 ms

64 bytes from 11.10.111.254: icmp_seq=9ttl=255 time=1.35 ms

64 bytes from 11.10.111.254: icmp_seq=10ttl=255 time=1.65 ms

64 bytes from 11.10.111.254: icmp_seq=11ttl=255 time=2.00 ms

64 bytes from 11.10.111.254: icmp_seq=12ttl=255 time=2.36 ms

注意,此實驗操作完成後記得要輸入kill  10653(看上面ping指令後面的那個數字)

二            參考資料

http://vbird.dic.ksu.edu.tw/

http://gnu.org/licenses/gpl.html

man手冊

繼續閱讀