在 Linux 下,用 nohup 启动的程序通常会把输出重定向到当前目录的 nohup.out,或者你手动指定的日志文件。实时查看这些日志,常用下面几种方式:
tail -f实时跟踪日志文件末尾的新内容。
tail -f nohup.out
如果你指定了日志文件:
nohup java -jar app.jar > app.log 2>&1 &
查看方式:
tail -f app.log
✅ 最推荐、最常用
tail -f nohup.out app.log
tail nohup.out
less +F nohup.out
操作说明:
tail -f)Ctrl + C 暂停Shift + F 继续实时跟踪q 退出适合日志很长、需要翻看历史的情况 ✅
确认进程是否还在运行:
ps -ef | grep your_program
或:
jobs
确认文件是否在被写入:
lsof nohup.out
可以清空而不影响程序:
: > nohup.out
⚠️ 不要用
rm nohup.out,否则程序可能继续写向已删除文件,磁盘不会释放
nohup ./app > app.log 2>&1 &
或按日期滚动(配合 logrotate):
nohup ./app >> app_$(date +%Y%m%d).log 2>&1 &
| 场景 | 命令 |
|---|---|
| 实时查看 | tail -f nohup.out |
| 查看并翻页 | less +F nohup.out |
| 查看最后 N 行 | tail -n 100 nohup.out |
| 清空日志 | : > nohup.out |
如果你是 Java / Python / Node / Shell 程序,我也可以给你更合适的日志方案。