温馨提示×

nohup日志如何查看内容

小樊
67
2026-08-31 08:23:37
栏目: 编程语言

使用 nohup 运行程序时,默认会把输出(stdout/stderr)写入当前目录下的 nohup.out 文件。查看日志常用下面几种方式:


一、直接查看 nohup.out 内容

1️⃣ 查看全部内容

cat nohup.out

2️⃣ 分页查看(推荐)

less nohup.out

常用操作:

  • q 退出
  • G 跳到文件末尾
  • g 跳到文件开头

二、实时查看日志(最常用 ✅)

tail -f nohup.out
  • 实时滚动显示日志
  • Ctrl + C 退出

只看最后 100 行:

tail -n 100 nohup.out

三、查找关键字

grep "ERROR" nohup.out

实时过滤:

tail -f nohup.out | grep "ERROR"

四、如果日志不在当前目录

1️⃣ 查找 nohup.out

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

2️⃣ 启动时指定了日志文件

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

查看方式:

tail -f app.log

五、查看 nohup 进程是否还在运行

ps -ef | grep 程序名

或

jobs -l

六、清理或清空日志(不影响进程)

: > nohup.out

或

truncate -s 0 nohup.out

七、推荐的最佳实践 ✅

启动程序时明确日志路径:

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

这样日志管理更清晰。


如果你愿意,可以把你用的 启动命令 或 系统(Linux / macOS) 发我,我可以给你更精准的查看方式。

0 踩