在 Debian(以及大多数 Linux 发行版)中,nohup 常用来在退出终端后继续运行程序,同时可以把输出记录到日志文件。
下面是常见用法和说明。
nohup command > output.log 2>&1 &
说明:
nohup:忽略挂断信号(SIGHUP)command:你要运行的命令> output.log:标准输出重定向到 output.log2>&1:错误输出也写入同一个日志&:后台运行示例:
nohup python app.py > app.log 2>&1 &
nohup command > stdout.log 2> stderr.log &
或者:
nohup ./start.sh > run.log 2> error.log &
默认 > 会覆盖文件,如果想追加:
nohup command >> output.log 2>&1 &
如果不重定向,nohup 默认会生成 nohup.out:
nohup command &
一般不建议,容易占空间。
jobs
查看进程:
ps aux | grep command
结束进程:
kill PID
如果是长期服务,推荐:
systemdscreentmux例如 systemd 可以更规范地管理日志(journalctl)。
如果你有具体命令或场景(比如 Python / Java / Shell 脚本),我可以给你更精确的示例。