温馨提示×

nohup日志怎么查看

小樊
62
2026-07-21 17:15:36
栏目: 编程语言

nohup 的日志通常输出到 当前目录下的 nohup.out 文件,除非你在启动时重定向了输出。下面按常见场景说明怎么查看。


一、默认情况(最常见)

nohup python app.py &

日志文件:

nohup.out

查看方式:

实时查看

tail -f nohup.out

查看最后 100 行

tail -n 100 nohup.out

分页查看

less nohup.out

搜索关键字

grep "ERROR" nohup.out

二、手动指定日志文件(推荐)

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

查看日志:

tail -f app.log

说明:

  • > app.log:标准输出
  • 2>&1:错误输出也写入同一个文件

三、只记录错误日志

nohup python app.py > /dev/null 2> error.log &

查看错误:

tail -f error.log

四、nohup.out 在哪?

  • 默认在 执行 nohup 命令时所在的目录
  • 如果不确定:
find / -name nohup.out 2>/dev/null

五、查看进程是否还在

ps -ef | grep app.py

或:

jobs -l

六、清空过大的 nohup.out(不中断程序)

: > nohup.out

或:

truncate -s 0 nohup.out

七、建议(生产环境)

✅ 使用:

nohup xxx > logs/app.log 2>&1 &

✅ 或配合:

  • logrotate 日志滚动
  • supervisor / systemd 管理进程

如果你愿意,可以把你的 启动命令贴出来,我可以帮你精确判断日志在哪、怎么看。

0