nohup 命令在 Linux 中用于在后台运行程序,并默认将输出重定向到日志文件。以下是常见的用法和说明:
nohup command &
nohup.out
$HOME/nohup.out
nohup command > app.log 2>&1 &
含义:
> app.log:stdout 写入 app.log2>&1:stderr 也合并到 stdout&:后台运行✅ 最常用方式
nohup command > stdout.log 2> stderr.log &
nohup command > /dev/null 2>&1 &
nohup command >> app.log 2>&1 &
>> 表示追加写入tail -f app.log
或
tail -f nohup.out
jobs
或
ps -ef | grep command
nohup java -jar app.jar > app.log 2>&1 &
nohup 不会自动关闭程序,需要手动 killlogrotate如果你有具体场景(如 Java / Python / Shell 脚本 / Docker),我可以给你更精确的示例。