在 CentOS 上,nohup 本身不会自动生成专门的“nohup 日志文件”,它只是让程序忽略 HUP 信号并在后台运行。日志输出到哪里,取决于你启动命令时怎么重定向的。下面分几种常见情况说明。
如果你是这样启动的:
nohup command &
那么:
stdout)和标准错误(stderr)默认会写入当前目录下的:nohup.out
cat nohup.out
less nohup.out
tail -f nohup.out
如果当前目录不可写,nohup.out 可能会写到:
$HOME/nohup.out
如果你是这样启动的:
nohup command > app.log 2>&1 &
或者:
nohup command > app.log 2> error.log &
那么日志就在你指定的文件里:
tail -f app.log
ps -ef | grep command
或:
pgrep -a command
ls -l /proc/PID/fd
常见输出:
1 -> /home/user/app.log
2 -> /home/user/app.log
说明:
1 = stdout2 = stderrnohup java -jar app.jar > app.log 2>&1 &
查看:
tail -f app.log
nohup python3 main.py > run.log 2>&1 &
nohup ./start.sh > start.log 2>&1 &
# 清空日志(不删文件)
: > nohup.out
或:
truncate -s 0 nohup.out
nohup command > logs/app.log 2>&1 &
避免:
nohup.out| 启动方式 | 日志位置 |
|---|---|
nohup cmd & |
nohup.out |
nohup cmd > a.log 2>&1 & |
a.log |
| 忘记重定向 | /proc/PID/fd |
| 实时查看 | tail -f xxx.log |
如果你愿意,可以把**你具体的启动命令或程序类型(Java / Python / Shell)**发出来,我可以帮你精确判断日志在哪、怎么查。