在 Linux 中,nohup 默认会把输出写到当前目录下的 nohup.out 文件。如果你想自定义日志重定向,常见用法如下:
nohup command > app.log 2>&1 &
含义:
> app.log:标准输出重定向到 app.log2>&1:标准错误也重定向到标准输出(即同一个文件)&:后台运行✅ 最常用
nohup command > app.log &
⚠️ 此时 stderr 仍会输出到 nohup.out
nohup command 2> error.log &
nohup command > app.log 2> error.log &
nohup command >> app.log 2>&1 &
>>:追加写入nohup command > /dev/null 2>&1 &
cd /opt/app
nohup ./start.sh > logs/app.log 2>&1 &
jobs
或
ps -ef | grep command
nohup java -jar app.jar > app.log 2>&1 &
nohup command >> app.log 2>&1 &
如果你愿意,可以告诉我:
我可以帮你给出更合适的方案(比如 logrotate 或 cronolog)。