nohup 命令通常会把输出重定向到当前目录下的 nohup.out 文件(或者你手动指定的日志文件)。所谓“导出 nohup 日志文件”,一般是指查看、复制、下载或分割这个日志文件。下面按常见场景说明。
如果你是这样启动的:
nohup python app.py &
日志默认在:
./nohup.out
如果你指定了日志:
nohup python app.py > app.log 2>&1 &
日志就是:
app.log
tail -f nohup.out
tail -n 100 nohup.out
cat nohup.out
cp nohup.out /home/user/logs/
cp nohup.out nohup_20260121.out
scp user@server_ip:/path/nohup.out ./local_dir/
rsync -avz user@server:/path/nohup.out ./
sed -n '1000,2000p' nohup.out > part.log
grep "ERROR" nohup.out > error.log
du -h nohup.out
> nohup.out
或
truncate -s 0 nohup.out
split -l 100000 nohup.out nohup_part_
nohup python app.py >> app.log 2>&1 &
并配合 logrotate 或定时清理。
如果你能说清楚:
我可以给你更精确的一条命令。