在 nohup 运行程序时,常用的实时查看日志的方法如下:
如果你是这样启动的:
nohup python app.py &
日志默认写入当前目录的 nohup.out。
tail -f nohup.out
nohup python app.py > app.log 2>&1 &
实时查看:
tail -f app.log
tail -f app.log # 实时跟踪
tail -F app.log # 文件被重建也能继续跟踪(推荐)
tail -n 100 app.log # 查看最后 100 行
如果分开写了:
nohup python app.py > out.log 2> err.log &
同时查看:
tail -f out.log err.log
tail -f app.log | grep ERROR
less +F app.log
F:实时跟踪Ctrl + C:暂停Shift + F:继续跟踪jobs
ps -ef | grep app.py
python -u app.py
du -h nohup.out
可清空:
: > nohup.out
如果你愿意,可以把你的启动命令贴出来,我可以帮你给出最合适的实时查看方式。