每天一個linux命令14-tail

1. 命令解析

命令用途

把文件的末尾N行顯示到標準輸出,默認顯示10行溶握,還可通過 tail -f file 來持續(xù)輸出文件的數(shù)據(jù)。

命令格式

tail [OPTION]... [FILE]...

命令參數(shù)

-c, --bytes=K output the last K bytes; or use -c +K to output
bytes starting with the Kth of each file
-f, --follow[={name|descriptor}]
output appended data as the file grows;
an absent option argument means 'descriptor'
-F same as --follow=name --retry
-n, --lines=K output the last K lines, instead of the last 10;
or use -n +K to output starting with the Kth
--max-unchanged-stats=N
with --follow=name, reopen a FILE which has not
changed size after N (default 5) iterations
to see if it has been unlinked or renamed
(this is the usual case of rotated log files);
with inotify, this option is rarely useful
--pid=PID with -f, terminate after process ID, PID dies
-q, --quiet, --silent never output headers giving file names
--retry keep trying to open a file if it is inaccessible
-s, --sleep-interval=N with -f, sleep for approximately N seconds
(default 1.0) between iterations;
with inotify and --pid=P, check process P at
least once every N seconds

2. 示例

2.1 顯示文件末尾10行

[root@test headTest]# tail hisotry.log 
  213  less history.log 
  214  cd /root/test
  215  ls
  216  mkdir headTest
  217  ls
  218  cd headTest/
  219  ls
  220  head --help
  221  history | head
  222  history > hisotry.log

2.2 顯示文件末尾5行 -n

[root@test headTest]# tail -5 hisotry.log 
  218  cd headTest/
  219  ls
  220  head --help
  221  history | head
  222  history > hisotry.log

2.3 實時跟蹤文件(默認1秒刷新一次) -f

[root@test headTest]# ping localhost > ping.log&
[1] 4971
[root@test headTest]# tail -f ping.log
PING localhost (127.0.0.1) 56(84) bytes of data.
64 bytes from localhost (127.0.0.1): icmp_seq=1 ttl=64 time=0.011 ms
64 bytes from localhost (127.0.0.1): icmp_seq=2 ttl=64 time=0.036 ms
64 bytes from localhost (127.0.0.1): icmp_seq=3 ttl=64 time=0.051 ms

通過CTRL+C結(jié)束實時監(jiān)控

2.4 定時實時跟蹤文件 -fs

[root@test headTest]# ping localhost > ping.log&
[2] 5116
[root@test headTest]# tail -fs2 ping.log
64 bytes from localhost (127.0.0.1): icmp_seq=10 ttl=64 time=0.036 ms
64 bytes from localhost (127.0.0.1): icmp_seq=220 ttl=64 time=0.024 ms
64 bytes from localhost (127.0.0.1): icmp_seq=221 ttl=64 time=0.024 ms
64 bytes from localhost (127.0.0.1): icmp_seq=222 ttl=64 time=0.030 ms
64 bytes from localhost (127.0.0.1): icmp_seq=223 ttl=64 time=0.081 ms

每隔2秒刷新蒸播,顯示文件最新內(nèi)容

2.5 從第5行開始顯示剩余所有內(nèi)容 -n +N

[root@test headTest]# tail -n +5 ping.log
64 bytes from localhost (127.0.0.1): icmp_seq=4 ttl=64 time=0.081 ms
64 bytes from localhost (127.0.0.1): icmp_seq=5 ttl=64 time=0.050 ms
64 bytes from localhost (127.0.0.1): icmp_seq=6 ttl=64 time=0.026 ms
64 bytes from localhost (127.0.0.1): icmp_seq=7 ttl=64 time=0.029 ms
...省略...

2.6 顯示多個文件

root@test headTest]# tail -n 5 hisotry.log ping.log 
==> hisotry.log <==
  218  cd headTest/
  219  ls
  220  head --help
  221  history | head
  222  history > hisotry.log

==> ping.log <==
64 bytes from localhost (127.0.0.1): icmp_seq=331 ttl=64 time=0.062 ms
64 bytes from localhost (127.0.0.1): icmp_seq=332 ttl=64 time=0.030 ms
64 bytes from localhost (127.0.0.1): icmp_seq=333 ttl=64 time=0.037 ms
64 bytes from localhost (127.0.0.1): icmp_seq=334 ttl=64 time=0.024 ms
64 bytes from localhost (127.0.0.1): icmp_seq=335 ttl=64 time=0.025 ms

2.7 不顯示文件名 -q

[root@test headTest]# tail -qn 5 hisotry.log ping.log 
  218  cd headTest/
  219  ls
  220  head --help
  221  history | head
  222  history > hisotry.log
64 bytes from localhost (127.0.0.1): icmp_seq=373 ttl=64 time=0.023 ms
64 bytes from localhost (127.0.0.1): icmp_seq=374 ttl=64 time=0.023 ms
64 bytes from localhost (127.0.0.1): icmp_seq=375 ttl=64 time=0.044 ms
64 bytes from localhost (127.0.0.1): icmp_seq=376 ttl=64 time=0.032 ms
64 bytes from localhost (127.0.0.1): icmp_seq=377 ttl=64 time=0.030 ms
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末睡榆,一起剝皮案震驚了整個濱河市,隨后出現(xiàn)的幾起案子袍榆,更是在濱河造成了極大的恐慌胀屿,老刑警劉巖,帶你破解...
    沈念sama閱讀 222,627評論 6 517
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件包雀,死亡現(xiàn)場離奇詭異宿崭,居然都是意外死亡,警方通過查閱死者的電腦和手機才写,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 95,180評論 3 399
  • 文/潘曉璐 我一進店門葡兑,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人赞草,你說我怎么就攤上這事讹堤。” “怎么了厨疙?”我有些...
    開封第一講書人閱讀 169,346評論 0 362
  • 文/不壞的土叔 我叫張陵洲守,是天一觀的道長。 經(jīng)常有香客問我沾凄,道長梗醇,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 60,097評論 1 300
  • 正文 為了忘掉前任撒蟀,我火速辦了婚禮叙谨,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘牙肝。我一直安慰自己唉俗,他們只是感情好嗤朴,可當我...
    茶點故事閱讀 69,100評論 6 398
  • 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著虫溜,像睡著了一般雹姊。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上衡楞,一...
    開封第一講書人閱讀 52,696評論 1 312
  • 那天吱雏,我揣著相機與錄音,去河邊找鬼瘾境。 笑死歧杏,一個胖子當著我的面吹牛,可吹牛的內(nèi)容都是我干的迷守。 我是一名探鬼主播犬绒,決...
    沈念sama閱讀 41,165評論 3 422
  • 文/蒼蘭香墨 我猛地睜開眼,長吁一口氣:“原來是場噩夢啊……” “哼兑凿!你這毒婦竟也來了凯力?” 一聲冷哼從身側(cè)響起,我...
    開封第一講書人閱讀 40,108評論 0 277
  • 序言:老撾萬榮一對情侶失蹤礼华,失蹤者是張志新(化名)和其女友劉穎咐鹤,沒想到半個月后,有當?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體圣絮,經(jīng)...
    沈念sama閱讀 46,646評論 1 319
  • 正文 獨居荒郊野嶺守林人離奇死亡祈惶,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 38,709評論 3 342
  • 正文 我和宋清朗相戀三年,在試婚紗的時候發(fā)現(xiàn)自己被綠了扮匠。 大學(xué)時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片捧请。...
    茶點故事閱讀 40,861評論 1 353
  • 序言:一個原本活蹦亂跳的男人離奇死亡,死狀恐怖餐禁,靈堂內(nèi)的尸體忽然破棺而出血久,到底是詐尸還是另有隱情,我是刑警寧澤帮非,帶...
    沈念sama閱讀 36,527評論 5 351
  • 正文 年R本政府宣布氧吐,位于F島的核電站,受9級特大地震影響末盔,放射性物質(zhì)發(fā)生泄漏筑舅。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點故事閱讀 42,196評論 3 336
  • 文/蒙蒙 一陨舱、第九天 我趴在偏房一處隱蔽的房頂上張望翠拣。 院中可真熱鬧,春花似錦游盲、人聲如沸误墓。這莊子的主人今日做“春日...
    開封第一講書人閱讀 32,698評論 0 25
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽谜慌。三九已至然想,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間欣范,已是汗流浹背变泄。 一陣腳步聲響...
    開封第一講書人閱讀 33,804評論 1 274
  • 我被黑心中介騙來泰國打工, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留恼琼,地道東北人妨蛹。 一個月前我還...
    沈念sama閱讀 49,287評論 3 379
  • 正文 我出身青樓,卻偏偏與公主長得像晴竞,于是被迫代替她去往敵國和親蛙卤。 傳聞我的和親對象是個殘疾皇子,可洞房花燭夜當晚...
    茶點故事閱讀 45,860評論 2 361

推薦閱讀更多精彩內(nèi)容

  • Spring Cloud為開發(fā)人員提供了快速構(gòu)建分布式系統(tǒng)中一些常見模式的工具(例如配置管理噩死,服務(wù)發(fā)現(xiàn)表窘,斷路器,智...
    卡卡羅2017閱讀 134,716評論 18 139
  • linux資料總章2.1 1.0寫的不好抱歉 但是2.0已經(jīng)改了很多 但是錯誤還是無法避免 以后資料會慢慢更新 大...
    數(shù)據(jù)革命閱讀 12,176評論 2 33
  • 我是一個喜歡在家吃飯的人甜滨,一般不太下館子×鲂洌可是什么吃多了都會膩衣摩,下館子就作為調(diào)劑,偶爾沾些大油葷腥捂敌,放縱一下腸胃艾扮,...
    Betty0614203閱讀 243評論 0 0
  • 夜。 無星光閃爍占婉, 只見小飛蟲在路燈下晃動泡嘴。 無微風(fēng)徐來, 只聽老蟬不停歇的嘶喊逆济。 夜酌予, 枝頭一抹絢爛, 悄悄吐露...
    冬至而已閱讀 124評論 1 1
  • 《孩子奖慌,把你的手給我》D2學(xué)而思20170112 “語言暴力像一把消音槍抛虫, 謀殺了孩子的尊嚴和人生, 除了當時的痛...
    遙遠曉然閱讀 775評論 0 0