nohup 本身只是“忽略挂断信号并运行命令”,真正需要分析的是它重定向出来的日志文件(通常是 nohup.out 或你指定的文件)。下面从定位日志 → 基础查看 → 问题排查 → 进阶分析逐步说明。
nohup command &
日志默认写入:
nohup.out
(在当前工作目录)
常见写法:
nohup python app.py > app.log 2>&1 &
或
nohup ./start.sh >> run.log 2>&1 &
查看进程和日志路径:
ps -ef | grep 进程名
ls -lh *.log nohup.out
tail -f nohup.out
或
tail -100f app.log
退出:Ctrl + C
tail -n 200 nohup.out
head -n 100 nohup.out
less nohup.out
G 跳到末尾/关键字 搜索q 退出重点看 错误日志
grep -i error nohup.out
grep -i exception nohup.out
常见原因:
ps -ef | grep 程序名
或
jobs -l
如果进程没了,但日志停在某一行:
dmesg | grep -i killed
或
journalctl -xe | grep 程序名
grep "2026-01-21 10:" nohup.out
grep -c ERROR app.log
grep -A 5 -B 5 "NullPointer" nohup.out
(前后各 5 行,定位上下文)
gzip nohup.out
zless nohup.out.gz
✅ 不要只靠 nohup.out
nohup app >> app_$(date +%F).log 2>&1 &
✅ 程序内做好日志分级
✅ 定期清理
logrotate
如果你愿意,可以补充:
我可以直接帮你读日志、定位问题。