nohup 命令默认会把输出重定向到当前目录下的 nohup.out 文件。查看方式取决于你启动程序时的具体写法。
nohup python app.py &
输出文件:
nohup.out
查看方式:
# 查看全部
cat nohup.out
# 实时查看(最常用)
tail -f nohup.out
# 查看最后 100 行
tail -n 100 nohup.out
如果你是这样启动的:
nohup python app.py > app.log 2>&1 &
那么日志在:
app.log
查看方式:
tail -f app.log
说明:
> app.log:标准输出2>&1:错误输出也写入同一个文件nohup python app.py > stdout.log 2> stderr.log &
查看:
tail -f stdout.log
tail -f stderr.log
ps -ef | grep app.py
或:
jobs -l
可能原因:
查找:
find / -name nohup.out 2>/dev/null
# 清空文件(不删文件)
: > nohup.out
或用 logrotate 做日志切割(生产环境推荐)。
tail -f nohup.out
Ctrl + C 只是退出 tail,不会影响程序运行。
如果你愿意,可以把你具体的 nohup 启动命令贴出来,我可以帮你精确判断日志在哪、怎么看最合适。