温馨提示×

centos nohup日志怎么看内容

小樊
43
2026-09-03 03:34:24
栏目: 智能运维

在 CentOS 里用 nohup 启动程序时,默认会把输出重定向到当前目录下的 nohup.out 文件(除非你自己指定了日志文件)。

1. 查看 nohup 日志内容

如果用了默认日志(nohup.out)

cat nohup.out

或者实时查看:

tail -f nohup.out

如果启动时指定了日志文件

比如你这样启动的:

nohup python app.py > app.log 2>&1 &

那就看 app.log

tail -f app.log

2. 常用查看命令

  • 查看最后 100 行:
tail -n 100 nohup.out
  • 实时跟踪日志(最常用):
tail -f nohup.out
  • 搜索关键字(如 ERROR):
grep ERROR nohup.out
  • 分页查看:
less nohup.out

(按 q 退出)


3. 确认日志文件在哪

如果找不到 nohup.out:

ls -l nohup.out

或:

find / -name nohup.out 2>/dev/null

也可以看进程启动命令:

ps -ef | grep 你的程序名

4. 小提示

  • 2>&1 表示标准错误也写入日志
  • 日志太大时建议定期切割(如 logrotate

如果你愿意,可以把你启动命令报错信息发出来,我可以帮你具体分析。

0