使用 nohup 运行程序时,默认会把输出(stdout/stderr)写入当前目录下的 nohup.out 文件。查看日志常用下面几种方式:
cat nohup.out
less nohup.out
常用操作:
q 退出G 跳到文件末尾g 跳到文件开头tail -f nohup.out
Ctrl + C 退出只看最后 100 行:
tail -n 100 nohup.out
grep "ERROR" nohup.out
实时过滤:
tail -f nohup.out | grep "ERROR"
find / -name nohup.out 2>/dev/null
nohup python app.py > app.log 2>&1 &
查看方式:
tail -f app.log
ps -ef | grep 程序名
或
jobs -l
: > nohup.out
或
truncate -s 0 nohup.out
启动程序时明确日志路径:
nohup python app.py > logs/app.log 2>&1 &
这样日志管理更清晰。
如果你愿意,可以把你用的 启动命令 或 系统(Linux / macOS) 发我,我可以给你更精准的查看方式。