在 Linux 中,nohup 命令通常会把输出重定向到 nohup.out 文件(除非你手动指定了输出文件)。搜索 nohup 日志内容,常见做法如下:
ls -l nohup.out
一般位于你启动 nohup 命令的当前目录。
例如:
nohup python app.py > app.log 2>&1 &
那么日志文件就是 app.log
grep(最常用)grep "关键字" nohup.out
grep -i "error" nohup.out
grep -n "Exception" nohup.out
grep -C 5 "error" nohup.out # 前后各5行
tail -f nohup.out | grep "error"
less(适合大文件)less nohup.out
常用操作:
/关键字:向下搜索?关键字:向上搜索n:下一个匹配N:上一个匹配q:退出tail 查看最新日志tail -n 100 nohup.out
实时查看:
tail -f nohup.out
cat + grep(不推荐大文件)cat nohup.out | grep "error"
find . -name nohup.out -mmin -10 -exec tail -n 100 {} \;
grep "2026-01-21 14:" nohup.out
查找可能的日志文件:
find / -name "nohup.out" 2>/dev/null
查看实时错误日志
tail -f nohup.out | grep -i error
查找异常堆栈
grep -n -A 10 "Exception" nohup.out
如果你愿意,可以把:
发给我,我可以帮你写一条精准的搜索命令。