tail
檔案與目錄
用法
tail -f [file]印出檔案結尾,並用 -f 持續跟著看;日誌輪替之後還想跟上,必須用 -F。
常用選項
| 選項 | 含義 |
|---|---|
| -n | Print the last N lines |
| -n +N | Start at line N instead of counting from the end |
| -f | Keep printing as the file grows |
| -F | Follow by name and reopen the file after log rotation |
| -c | Print the last N bytes |
| -r | BSD: print the lines in reverse order (GNU uses tac) |
範例
tail -f app.logWatches a log live; Ctrl-C stops.
tail -n +2 data.csvSkips the header line.
tail -F /var/log/nginx/access.logKeeps following after the log is rotated.
搬移、刪除和尋找。有些命令不會再問一次,所以順手加 -i 是在救自己。
怎麼看
- 方括號 [ ] 表示這部分可以不寫。
- 省略號 … 表示可以寫多個。
- 選項區分大小寫——有些命令裡 -r 和 -R 不是一回事。
常見問題
Q. tail 是做什麼的?
印出檔案結尾,並用 -f 持續跟著看;日誌輪替之後還想跟上,必須用 -F。
Q. 怎麼寫?
tail -f [file] —— 方括號表示可以省略的部分。
Q. 值得記的選項有幾個?
這裡列了 6 個,完整列表在 man tail。這條命令屬於檔案與目錄。
相關命令
man 手冊: man tail