在 Debian(以及大多数 Linux 发行版)中,nohup 常用来让进程在退出终端后继续运行,并默认把输出记录到日志文件。
下面按常见用法 → 推荐做法 → 实用示例来说明。
nohup command > output.log 2>&1 &
含义:
nohup:忽略挂断信号command:你要运行的程序或脚本> output.log:标准输出写入日志2>&1:错误输出也写入同一个日志&:后台运行示例:
nohup python3 app.py > app.log 2>&1 &
nohup command &
默认会生成:
nohup.out
(在当前目录)
查看日志:
tail -f nohup.out
nohup command > out.log 2> err.log &
nohup command >> app.log 2>&1 &
>:覆盖>>:追加nohup command >> app_$(date +%Y%m%d).log 2>&1 &
jobs
或
ps aux | grep command
结束进程:
kill PID
如果你在 Debian 上长期跑服务,更推荐使用:
systemdscreentmux例如 systemd 可自动管理日志(journalctl)
如果你能说一下具体运行什么程序(Python / Java / shell 脚本等),我可以给你更精确的命令。