在 CentOS 上,使用 nohup 启动程序时,输出默认会写入 nohup.out(或你重定向的文件)。实时查看日志常用下面几种方式:
nohup.out(最常用)tail -f nohup.out
如果文件在其他目录:
tail -f /path/to/nohup.out
✅ 适合查看程序实时输出
tail -n 100 -f nohup.out
-n 100:先显示最后 100 行-f:持续监控新内容less +F nohup.out
操作说明:
Ctrl + C:暂停自动滚动Shift + F:恢复实时跟踪q:退出✅ 适合日志很长的情况
例如启动时:
nohup java -jar app.jar > app.log 2>&1 &
查看日志:
tail -f app.log
tail -f nohup.out app.log
tail -f nohup.out | grep ERROR
或高亮显示:
tail -f nohup.out | grep --color ERROR
ps -ef | grep 程序名
或:
jobs
启动时:
nohup java -jar app.jar >> app.log 2>&1 &
或按天滚动(配合 logrotate):
logrotate
| 场景 | 推荐命令 |
|---|---|
| 实时查看 | tail -f nohup.out |
| 翻页查看 | less +F nohup.out |
| 过滤关键字 | tail -f nohup.out | grep ERROR |
| 自定义日志 | nohup xxx > xxx.log 2>&1 & |
如果你愿意,可以把**启动命令或程序类型(Java / Python / Shell)**发给我,我可以帮你给出更专业的日志方案。