在 CentOS(以及其它 Linux 发行版)中,nohup 常用于在后台运行程序,并且默认会将输出写入 nohup.out 文件。如果你想要自定义日志重定向,可以使用 Shell 的重定向功能。
下面按常见场景说明:
nohup your_command > app.log 2>&1 &
说明:
>:重定向标准输出(stdout)2>&1:将标准错误(stderr)也重定向到 stdout&:后台运行nohup your_command > app.out.log 2> app.err.log &
app.out.log:正常日志app.err.log:错误日志nohup your_command >> app.log 2>&1 &
>>:追加写入,而不是覆盖nohup your_command > /dev/null 2>&1 &
nohup /opt/app/start.sh > /var/log/app.log 2>&1 &
jobs
或
ps -ef | grep your_command
kill -9 PID
如果你有具体命令(如 Java、Python、Shell 脚本),我可以给你更精确的示例。