在 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
文件。