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