温馨提示×

怎样查看centos nohup日志

小樊
41
2026-09-27 09:03:04
栏目: 智能运维

在 CentOS 中,nohup 命令默认会把程序的**标准输出(stdout)和标准错误(stderr)**写入到当前目录下的 nohup.out 文件里。查看日志其实就是查看这个文件(或你指定的日志文件)。

下面按常见场景说明:


一、默认情况(未指定日志文件)

1. 查看 nohup.out

cat nohup.out

实时查看(最常用):

tail -f nohup.out

查看最后 100 行:

tail -n 100 nohup.out

二、启动时指定了日志文件

如果你是这样启动的:

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

那么日志就在 app.log:

tail -f app.log

说明:

  • >:重定向 stdout
  • 2>&1:把 stderr 也写进同一个文件
  • &:后台运行

三、不知道日志在哪了?

1. 查找 nohup.out

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

2. 查看进程对应的文件

ps -ef | grep 程序名

然后:

ls -l /proc/进程ID/fd

可以看到程序正在写哪个日志文件。


四、想分页查看大日志

less nohup.out
  • 按 空格 翻页
  • 按 q 退出

搜索内容:

grep "ERROR" nohup.out

五、常见问题

nohup.out 太大?

可以清空(不影响程序运行):

> nohup.out

推荐做法(生产环境)

nohup your_command >> app.log 2>&1 &

或用 systemd / supervisor 管理日志更规范。


如果你愿意,可以告诉我:

  • 你运行的命令是什么
  • 是否还能看到进程

我可以帮你精准定位日志文件。

0 踩