在 CentOS 上,使用 nohup 启动程序时,默认日志位置取决于你有没有重定向输出。
如果你是这样运行的:
nohup command &
那么:
nohup.out
查找方式:
ls -l nohup.out
pwd # 看当前目录
如果当前目录不可写,可能会写到:
~/nohup.out
如果你是这样运行的:
nohup command > app.log 2>&1 &
或
nohhup command >> /var/log/app.log 2>&1 &
那么日志就在你指定的文件里。
查找方法:
# 查看进程对应的文件
ps -ef | grep command
ls -l /proc/<PID>/fd
或全局搜:
find / -name "*.log" 2>/dev/null | grep app
ps -ef | grep 你的程序名
假设 PID 是 12345:
ls -l /proc/12345/fd
你会看到类似:
1 -> /root/app.log
2 -> /root/app.log
说明日志在 /root/app.log
如果你是:
systemctl start xxx
那不是 nohup,日志在:
journalctl -u 服务名
# 找 nohup.out
find / -name nohup.out 2>/dev/null
# 看进程打开的文件
lsof -p PID
# 实时看日志
tail -f 日志文件
如果你愿意,可以把你启动命令或程序名发出来,我可以直接帮你定位日志文件。