在 CentOS 中,nohup
命令用于在后台运行程序,即使关闭终端或断开连接,程序也会继续运行
nohup command1 ; nohup command2 &
这将首先运行 command1
,然后在后台运行 command2
。
nohup command1 && nohup command2 &
这将首先运行 command1
,如果 command1
成功执行,则在后台运行 command2
。
nohup
命令和子 shell:nohup bash -c 'command1; command2' &
这将在后台运行一个子 shell,依次执行 command1
和 command2
。
请注意,为了避免输出混乱,建议将每个命令的输出重定向到不同的日志文件中。例如:
nohup command1 > output1.log 2>&1 &
nohup command2 > output2.log 2>&1 &
这将把 command1
的标准输出和错误输出重定向到 output1.log
文件,把 command2
的标准输出和错误输出重定向到 output2.log
文件。