温馨提示×

centos如何查看nohup日志

小樊
48
2026-09-15 07:59:01
栏目: 智能运维

在 CentOS 中,nohup 命令默认会把程序的输出重定向到当前目录下的 nohup.out 文件(如果未显式指定输出文件)。查看日志的方法如下:


一、默认情况(nohup.out)

1. 查看 nohup.out 内容

cat nohup.out

2. 实时查看日志(最常用)

tail -f nohup.out

tail -F nohup.out   # 文件被重建也能继续跟踪

3. 查看最后 N 行

tail -n 100 nohup.out

4. 分页查看

less nohup.out

(按 q 退出)


二、指定了日志文件的情况

如果你启动时是这样的:

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

那么日志在 app.log

tail -f app.log

三、查找 nohup 日志文件位置

如果忘了日志在哪:

ls -l nohup.out

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

四、结合进程查看

ps -ef | grep 程序名

查看进程对应的文件描述符:

ls -l /proc/进程ID/fd

五、常用组合示例

# 实时查看并过滤错误
tail -f nohup.out | grep ERROR

# 查看日志大小
du -h nohup.out

如果你愿意,可以告诉我你 具体的启动命令,我可以帮你精确判断日志在哪里。

0