Linux tail 命令

Linux 命令大全 Linux 命令大全

tail 命令可用於查看檔的內容,有一個常用的參數 -f 常用於查閱正在改變的日誌檔。

tail -f filename 會把 filename 檔裏的最尾部的內容顯示在螢幕上,並且不斷刷新,只要 filename 更新就可以看到最新的檔內容。

命令格式:

tail [參數] [檔]  

參數:

  • -f 迴圈讀取
  • -q 不顯示處理資訊
  • -v 顯示詳細的處理資訊
  • -c<數目> 顯示的位元組數
  • -n<行數> 顯示檔的尾部 n 行內容
  • --pid=PID 與-f合用,表示在進程ID,PID死掉之後結束
  • -q, --quiet, --silent 從不輸出給出檔案名的首部
  • -s, --sleep-interval=S 與-f合用,表示在每次反復的間隔休眠S秒

實例

要顯示 notes.log 檔的最後 10 行,請輸入以下命令:

tail notes.log

要跟蹤名為 notes.log 的檔的增長情況,請輸入以下命令:

tail -f notes.log

此命令顯示 notes.log 檔的最後 10 行。當將某些行添加至 notes.log 檔時,tail 命令會繼續顯示這些行。 顯示一直繼續,直到您按下(Ctrl-C)組合鍵停止顯示。

顯示檔 notes.log 的內容,從第 20 行至檔末尾:

tail +20 notes.log

顯示檔 notes.log 的最後 10 個字元:

tail -c 10 notes.log

Linux 命令大全 Linux 命令大全