Linux教程網
Linux教程網
Linux教程網
您现在的位置: Linux教程網 >> UnixLinux >  >> Linux綜合 >> 學習 Linux

Linux tail 指令詳解:檢視檔案末尾與即時追蹤日誌

tail 指令用於顯示檔案末尾的內容。

語法:tail [參數] [參數值] [檔案名稱]

參數說明:

-n:從檔案末尾往前顯示指定的行數;
-f:顯示末尾指定行數,且當檔案有新內容寫入時持續動態輸出。

原始檔案 1.txt 共有 23 行:

[root@test tools]# cat 1.txt
1
2
3
...
23

查看末尾 5 行:

[root@test tools]# tail -n 5 1.txt
19
20
21
22
23

不帶參數時預設顯示末尾 10 行:

[root@test tools]# tail 1.txt
14
15
16
17
18
19
20
21
22
23

動態追蹤檔案尾部:

[root@test tools]# tail -f 1.txt
18
19
20
21
22
23
24
25
26
27

寫入新內容後會即時顯示:

[root@test tools]# tail -f 1.txt
...
27
new1
new2
new3
new4
new5

按 Ctrl+C 即可結束 tail -f。

Copyright © Linux教程網 All Rights Reserved