在 Debian(以及其他 Linux 发行版)中,nohup 默认会把程序输出重定向到当前目录的 nohup.out 文件。如果你想“关闭”或避免产生 nohup 日志,有以下几种常见做法:
nohup your_command > /dev/null 2>&1 &
说明:
> /dev/null:标准输出丢弃2>&1:错误输出也丢弃&:后台运行✅ 不会产生 nohup.out
nohup your_command > /dev/null &
或
nohup your_command 2> error.log &
nohup your_command > my.log 2>&1 &
ps aux | grep your_command
ls -l /proc/<PID>/fd
然后用 gdb 或 reredirect 工具重定向 fd(不推荐新手)
setsidsetsid your_command > /dev/null 2>&1 < /dev/null &
systemd(服务器程序推荐)[Service]
ExecStart=/path/to/your_command
StandardOutput=null
StandardError=null
systemctl start your_service
| 需求 | 命令 |
|---|---|
| 完全不写日志 | nohup cmd > /dev/null 2>&1 & |
| 不生成 nohup.out | 同上 |
| 写指定日志 | nohup cmd > log.txt 2>&1 & |
| 推荐方式 | systemd / setsid |
如果你能告诉我 具体命令或程序,我可以给你更精确的写法。