nohup 命令通常配合 > logfile 2>&1 & 或默认生成 nohup.out 来记录日志。检索 nohup 日志本质上就是对文本日志文件进行检索,常用方法如下:
# 默认情况
nohup python app.py & # 日志默认写在 ./nohup.out
# 常见自定义写法
nohup python app.py > app.log 2>&1 &
日志文件通常是:
nohup.outxxx.logtail -f nohup.out
Ctrl + C 退出只看最后 100 行:
tail -n 100 nohup.out
grep "ERROR" nohup.out
忽略大小写:
grep -i "error" nohup.out
显示行号:
grep -n "Exception" nohup.out
多个关键字(或):
grep -E "ERROR|WARN" nohup.out
多个关键字(与):
grep "ERROR" nohup.out | grep "timeout"
tail -f nohup.out | grep "ERROR"
如果日志带时间戳(如 2026-01-21 10:00:00):
grep "2026-01-21 10:" nohup.out
grep -c "ERROR" nohup.out
grep -A 10 "ERROR" nohup.out # 后10行
grep -B 10 "ERROR" nohup.out # 前10行
grep -C 10 "ERROR" nohup.out # 前后各10行
less nohup.out
/关键字 搜索n 下一个,N 上一个q 退出sed -n '/2026-01-21 10:00/,/2026-01-21 11:00/p' nohup.out
tail -f nohup.out | grep -E "ERROR|Exception"
或
grep -C 20 "OutOfMemory" nohup.out
如果你愿意,可以告诉我:
我可以直接帮你写精准检索命令。