在 Linux 中,使用 nohup 运行命令时,默认会把输出写入当前目录的 nohup.out 文件。如果你想自定义日志重定向,可以用 shell 的重定向语法。
nohup your_command > output.log &
nohup your_command > output.log 2>&1 &
或者(等价写法,推荐):
nohup your_command &> output.log &
nohup your_command >> output.log 2>&1 &
>>表示追加,>表示覆盖
nohup your_command > /dev/null 2>&1 &
nohup your_command \
> stdout.log \
2> stderr.log &
nohup your_command > app_$(date +%Y%m%d).log 2>&1 &
nohup python app.py > app.log 2>&1 &
查看日志:
tail -f app.log
如果你有 具体命令或场景(如 Java / Python / shell 脚本),我可以给你更精确的写法。