在 CentOS(以及其他 Linux 发行版)中,nohup 通常和 & 一起使用来在后台运行程序,并重定向其输出日志。下面给你几种常见做法。
nohup your_command > output.log 2>&1 &
说明:
>:重定向标准输出(stdout)2>&1:把标准错误(stderr)也重定向到 stdout&:后台运行nohup 会生成 nohup.out,上面写法会改用 output.lognohup your_command &
日志会写入当前目录的:
nohup.out
如果当前目录不可写,会写到:
$HOME/nohup.out
nohup your_command 2> error.log > /dev/null &
error.lognohup your_command > stdout.log 2> stderr.log &
nohup your_command >> output.log 2>&1 &
>> 表示追加写入。
tail -f output.log
nohup your_command >> app.log 2>&1 &
✅ 后台运行
✅ 日志追加
✅ 标准错误也记录
如果你有具体命令(如 Java、Python、Shell 脚本),我可以给你更精确的示例。