系統(tǒng)之家 - 系統(tǒng)光盤下載網(wǎng)站!

當(dāng)前位置:系統(tǒng)之家 > 系統(tǒng)教程 > Linux下使用tail命令

Linux下如何使用tail命令指南

時(shí)間:2014-12-10 15:52:00 作者:qipeng 來(lái)源:系統(tǒng)之家 1. 掃描二維碼隨時(shí)看資訊 2. 請(qǐng)使用手機(jī)瀏覽器訪問(wèn): https://m.xitongzhijia.net/xtjc/20141210/32267.html 手機(jī)查看 評(píng)論

  如果head命令用于查看文件的頭部,那么tail命令就正好相反,tail命令主要用于查看文件內(nèi)容的結(jié)尾,下面小編就給大家詳細(xì)介紹下Linux下tail的用法吧。

 Linux下如何使用tail命令指南

  1.命令格式;

  tail[必要參數(shù)][選擇參數(shù)][文件]

  2.命令功能:

  用于顯示指定文件末尾內(nèi)容,不指定文件時(shí),作為輸入信息進(jìn)行處理。常用查看日志文件。

  3.命令參數(shù):

  -f 循環(huán)讀取

  -q 不顯示處理信息

  -v 顯示詳細(xì)的處理信息

  -c《數(shù)目》 顯示的字節(jié)數(shù)

  -n《行數(shù)》 顯示行數(shù)

  --pid=PID 與-f合用,表示在進(jìn)程ID,PID死掉之后結(jié)束。

  -q, --quiet, --silent 從不輸出給出文件名的首部

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

  4.使用實(shí)例:

  實(shí)例1:顯示文件末尾內(nèi)容

  命令:

  tail -n 5 log2014.log

  輸出:

 。踨oot@localhost test]# tail -n 5 log2014.log

  2014-09

  2014-10

  2014-11

  2014-12

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

  說(shuō)明:

  顯示文件最后5行內(nèi)容

  實(shí)例2:循環(huán)查看文件內(nèi)容

  命令:

  tail -f test.log

  輸出:

 。踨oot@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

 。踨oot@localhost ~]#

  說(shuō)明:

  ping 192.168.120.204 》 test.log & //在后臺(tái)ping遠(yuǎn)程主機(jī)。并輸出文件到test.log;這種做法也使用于一個(gè)以上的檔案監(jiān)視。用Ctrl+c來(lái)終止。

  實(shí)例3:從第5行開始顯示文件

  命令:

  tail -n +5 log2014.log

  輸出:

 。踨oot@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

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

  上面就是Linux下tail命令的用法介紹了,如果你需要查看文件的后面幾行內(nèi)容,那么就會(huì)用到tail命令,你可以參考上面的實(shí)例結(jié)合實(shí)際使用。

標(biāo)簽 命令 tail

發(fā)表評(píng)論

0

沒(méi)有更多評(píng)論了

評(píng)論就這些咯,讓大家也知道你的獨(dú)特見(jiàn)解

立即評(píng)論

以上留言僅代表用戶個(gè)人觀點(diǎn),不代表系統(tǒng)之家立場(chǎng)

其他版本軟件

熱門教程

人氣教程排行

Linux系統(tǒng)推薦

官方交流群 軟件收錄