nohup
(no hang-up)命令在 Linux 中用于在后臺運行程序,使其在用戶退出登錄后仍然繼續運行
nohup
后面,并在末尾添加 &
符號。例如:nohup your_command &
這將在后臺運行 your_command
,并將輸出重定向到名為 nohup.out
的文件。
nohup.out
文件。例如:nohup your_command > output.log 2>&1 &
這將把標準輸出和錯誤輸出都重定向到 output.log
文件。
;
組合多個命令:您可以使用分號(;
)將多個命令組合在一起。例如:nohup command1 ; command2 &
這將在后臺運行 command1
,然后運行 command2
。
&&
組合多個命令:如果您希望僅在 command1
成功執行后運行 command2
,可以使用 &&
。例如:nohup command1 && command2 &
這將在后臺運行 command1
,如果 command1
成功執行,則運行 command2
。
|
管道:您可以使用管道(|
)將一個命令的輸出作為另一個命令的輸入。例如:nohup command1 | command2 &
這將在后臺運行 command1
,并將輸出作為 command2
的輸入。
請注意,nohup
命令通常用于運行不需要用戶交互的程序。如果您需要在后臺運行需要用戶交互的程序,可以考慮使用 screen
或 tmux
等終端復用器。