在使用 nohup 运行程序时,默认会把输出写到 nohup.out。如果你想屏蔽(不记录)日志输出,可以把标准输出和标准错误重定向到“空设备”。
nohup your_command > /dev/null 2>&1 &
说明:
> /dev/null:标准输出(stdout)丢弃2>&1:标准错误(stderr)也重定向到 stdout&:后台运行nohup your_command > /dev/null &
nohup your_command 2> /dev/null &
nohup your_command > my.log 2>&1 &
有些程序会绕过 stdout 直接写文件,此时需要:
/dev/null如果你愿意,可以告诉我你具体运行的命令或程序(如 Java / Python / shell 脚本),我可以给你更精确的写法。