在 Debian(以及大多数 Linux 发行版)中,nohup 默认会把程序的**标准输出(stdout)和标准错误(stderr)**写入当前目录下的 nohup.out 文件。
下面分几种常见情况说明**“nohup 日志怎样导出”**。
nohup your_command &
日志位置:
./nohup.out
查看日志:
tail -f nohup.out
nohup your_command > app.log 2>&1 &
说明:
>:重定向 stdout2>&1:把 stderr 也写入同一文件&:后台运行nohup your_command > app.out 2> app.err &
app.out:正常日志app.err:错误日志nohup your_command >> app.log 2>&1 &
如果已经跑了 nohup,但日志在 nohup.out:
cp nohup.out app.log
或实时导出:
tail -f nohup.out > export.log
如果你经常需要导日志,建议:
screen
your_command
# Ctrl+A D 退出
或:
tmux
your_command
# Ctrl+B D
如果是长期服务,建议写成 service:
journalctl -u your_service.service -f
| 场景 | 命令 |
|---|---|
| 默认日志 | nohup cmd & → nohup.out |
| 指定日志 | nohup cmd > log 2>&1 & |
| 分开日志 | nohup cmd > out 2> err & |
| 实时查看 | tail -f log |
如果你能告诉我具体命令 / 程序(如 python、java、node),我可以给你更精准的导出方式。