在 Debian 系统中,使用 nohup 启动程序时,默认会把标准输出(stdout)和标准错误(stderr)写入到当前目录下的 nohup.out 文件。如果你想要导出 / 重定向 nohup 日志,常见做法如下:
nohup your_command > /path/to/logfile.log 2>&1 &
说明:
>:重定向标准输出2>&1:把标准错误也重定向到标准输出&:后台运行示例:
nohup python app.py > /var/log/app.log 2>&1 &
nohup your_command > app.log &
nohup your_command 2> error.log &
cp nohup.out /path/to/backup.log
tail -f nohup.out
导出到文件:
tail -f nohup.out > export.log
nohup your_command >> /path/to/logfile.log 2>&1 &
logrotate示例 /etc/logrotate.d/myapp:
/var/log/app.log {
daily
rotate 7
compress
missingok
notifempty
copytruncate
}
jobs
ps aux | grep your_command
如果你愿意,可以告诉我:
我可以给你更精确的命令。