在 Linux 中,nohup
命令用于在后台运行程序,即使关闭终端或断开连接,程序也会继续运行
nohup command > output.log 2>&1 &
这里,command
是你要运行的命令。>
将标准输出重定向到 output.log
文件。2>&1
表示将标准错误(文件描述符 2)重定向到标准输出(文件描述符 1),&
表示将命令放入后台运行。
nohup command > output.log 2> error.log &
这里,output.log
文件用于存储标准输出,error.log
文件用于存储标准错误。
nohup command >> output.log 2>&1 &
这里,>>
表示将输出追加到已存在的 output.log
文件,而不是覆盖它。
注意:在使用 nohup
命令时,建议使用绝对路径来指定命令和文件,以避免因环境变量或当前工作目录改变而导致的问题。