nohup 日志丢失通常不是 nohup 把日志“删了”,而是输出目标、重定向方式或程序行为出了问题。下面按最常见原因逐一说明,并给出对应解决方案。
nohup.out)nohup ./app
nohup.outnohup.out 被删除 / 覆盖✅ 建议做法
nohup ./app > app.log 2>&1 &
✅ 解决方法
nohup python -u app.py > app.log 2>&1 &
或
print("xxx", flush=True)
nohup java -Djava.util.logging.config.file=logging.properties ...
nohup ./app > app.log &
✅ stdout 在 app.log
❌ stderr 可能:
nohup.out✅ 正确写法
nohup ./app > app.log 2>&1 &
rm app.log
ls 看不到文件✅ 检查:
lsof -p PID
✅ 恢复(如 inode 还在):
cp /proc/PID/fd/3 app.log
nohup 根本没用到✅ 检查:
ps -fp PID
或直接看程序配置
nohup ./app > app.log
nohup ./app > app.log
✅ 用追加模式:
nohup ./app >> app.log 2>&1 &
df -h
df -i
nohup ./app >> app.log 2>&1 &
nohup ./app >> app_$(date +%Y%m%d).log 2>&1 &
或使用:
logrotatesystemdsupervisor如果你愿意,可以贴出:
我可以帮你精确判断是哪一种情况。