介紹
tail
指令用來檢視檔案的最後十行。
語法
tail [options] [files]
常用的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.
範例
你可以檢視檔案的最後十行:
⤍ tail myfile
⤍ nl myfile | tail
使用-f
選項,會讓tail
指令持續讀取檔案,只要新資料被寫入,就會馬上顯示出來,常被用來讀取log files
:
⤍ tail -f /var/log/syslog
發佈留言