LINUX

LINUX TAIL指令

介紹

tail指令用來檢視檔案的最後十行。

語法

tail [options] [files]
Code language: Bash (bash)

常用的options

-n N Print the last N lines of the file instead of 10. -N Same as -n N. -n +N Print all lines except the first N. -c N Print the last N bytes of the file. -f Keep the file open, and whenever lines are appended to the file, print them. This is extremely useful. Add the --retry option if the file doesn't exist yet, but you want to wait for it to exist. -q Quiet mode: when processing more than one file, don't print a banner above each file. Normally tail prints a banner containing the filename.
Code language: plaintext (plaintext)

範例

你可以檢視檔案的最後十行:

⤍ tail myfile
Code language: Bash (bash)

搭配nl指令管線,可以顯示行數:

⤍ nl myfile | tail
Code language: Bash (bash)

使用-f選項,會讓tail指令持續讀取檔案,只要新資料被寫入,就會馬上顯示出來,常被用來讀取log files

⤍ tail -f /var/log/syslog
Code language: Bash (bash)

發佈留言