在 Debian(或其他 Linux 系统)里,nohup 运行程序时,默认会把输出写到当前目录的 nohup.out 文件。如果你想知道“怎么导出日志”,一般有以下几种常见情况和做法:
nohup your_command > nohup.log 2>&1 &
说明:
>:标准输出重定向到 nohup.log2>&1:标准错误也写入同一个文件&:后台运行✅ 日志就在 nohup.log
nohup your_command \
> stdout.log \
2> stderr.log \
&
stdout.log:正常输出stderr.log:错误日志nohup your_command >> app.log 2>&1 &
如果已经用默认方式运行了:
cat nohup.out
导出到其他地方:
cp nohup.out /var/log/myapp.log
或实时查看:
tail -f nohup.out
使用 logrotate 或 nohup + cronolog:
nohup your_command 2>&1 | cronolog /var/log/app/%Y%m%d.log &
jobs
ps aux | grep your_command
nohup python3 app.py > /var/log/app.log 2>&1 &
然后:
tail -f /var/log/app.log
如果你能告诉我:
我可以给你更精确的方案。