在 CentOS(以及大多数 Linux 系统)中,nohup 命令默认会把输出写入当前目录的 nohup.out 文件。如果你想自定义日志输出位置,可以通过以下几种方式实现。
> 重定向标准输出nohup your_command > /path/to/log.log 2>&1 &
说明:
>:重定向标准输出(stdout)2>&1:把标准错误(stderr)也重定向到同一个地方&:后台运行✅ 推荐用法,最常用
nohup your_command > /path/to/out.log 2> /path/to/err.log &
out.log:正常日志err.log:错误日志nohup your_command >> /path/to/log.log 2>&1 &
>>:追加写入(不会清空原日志)nohup your_command > /dev/null 2>&1 &
适用于不需要日志的场景。
nohup python app.py > /var/log/app.log 2>&1 &
查看日志:
tail -f /var/log/app.log
logrotate)如果你有具体命令或场景(如 Java / Python / Shell 脚本),我可以给你更精确的示例。