nohup 默认会把输出写到当前目录下的 nohup.out 文件里。如果你不想产生日志输出,可以把标准输出和错误输出都重定向到 /dev/null。
nohup your_command >/dev/null 2>&1 &
说明:
>/dev/null:标准输出丢弃2>&1:错误输出也重定向到标准输出(一起丢弃)&:后台运行nohup your_command >/dev/null &
nohup your_command 2>/dev/null &
nohup your_command >my.log 2>&1 &
如果程序已经在跑,可以:
# 清空 nohup.out,不删除文件
: > nohup.out
⚠️ 注意:
rm nohup.out,程序可能仍然持有文件句柄,磁盘空间不会释放。setsid(更干净,不产生 nohup.out)setsid your_command >/dev/null 2>&1 &
如果你愿意,可以告诉我你运行的是 Java / Python / Shell / 某个具体程序,我可以给你一个更合适的示例。