在 Debian(或其他 Linux 系统)里,nohup 本身不支持直接关闭日志,它的默认行为是:
nohup command > nohup.out 2>&1 &
也就是说,日志本质上是重定向产生的,而不是 nohup 自己“写”的。
/dev/nullnohup command > /dev/null 2>&1 &
说明:
> /dev/null:标准输出不保存2>&1:错误输出也丢弃nohup command > /dev/null &
nohup command &> /dev/null &
ps aux | grep command
kill PID
rm -f nohup.out
: > nohup.out
# 或
truncate -s 0 nohup.out
⚠️ 这只是清空,不是关闭,程序仍会继续写。
setsid(不依赖 nohup)setsid command > /dev/null 2>&1 &
[Service]
StandardOutput=null
StandardError=null
| 需求 | 命令 |
|---|---|
| 关闭所有日志 | nohup cmd > /dev/null 2>&1 & |
| 不生成 nohup.out | 重定向到 /dev/null |
| 清空已有日志 | truncate -s 0 nohup.out |
如果你愿意,可以告诉我具体运行的命令,我可以帮你写一条最合适的启动方式。