在 CentOS 上用 nohup 启动程序时,日志一般写在:
nohup.out(默认)nohup xxx > app.log 2>&1 &下面是常用的日志检索方法。
ls -l nohup.out
# 或
ls -l /path/to/your.log
查看进程对应的日志文件:
ps -ef | grep 程序名
tail -f nohup.out
或
tail -f /path/to/app.log
只看最后 100 行并从现在开始跟踪:
tail -n 100 -f nohup.out
grep "ERROR" nohup.out
忽略大小写:
grep -i "error" nohup.out
显示行号:
grep -n "ERROR" nohup.out
tail -f nohup.out | grep "ERROR"
多个关键字(或):
tail -f nohup.out | grep -E "ERROR|WARN"
如果日志有时间戳:
grep "2026-01-21 10:" nohup.out
或按行范围:
sed -n '100,200p' nohup.out
grep -c "ERROR" nohup.out
less nohup.out
进入后:
/关键字 搜索n 下一个Shift+n 上一个G 跳到末尾q 退出推荐用 logrotate,或启动时就重定向:
nohup java -jar app.jar >> app.log 2>&1 &
nohup.outsudo如果你愿意,可以告诉我:
我可以给你更准确的命令。