溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

linux命令中tail有什么用

發布時間:2021-08-26 09:21:25 來源:億速云 閱讀:137 作者:小新 欄目:開發技術

這篇文章給大家分享的是有關linux命令中tail有什么用的內容。小編覺得挺實用的,因此分享給大家做個參考,一起跟隨小編過來看看吧。

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

命令格式

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

命令參數

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

使用實例

實例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
==============================

感謝各位的閱讀!關于“linux命令中tail有什么用”這篇文章就分享到這里了,希望以上內容可以對大家有一定的幫助,讓大家可以學到更多知識,如果覺得文章不錯,可以把它分享出去讓更多的人看到吧!

向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

亚洲午夜精品一区二区_中文无码日韩欧免_久久香蕉精品视频_欧美主播一区二区三区美女