在Linux中,nohup
命令用于在后臺運行程序,即使關閉終端或斷開連接,程序也會繼續運行
nohup command > output.log 2>&1 &
這里,command
是你要運行的命令。>
表示將標準輸出重定向到output.log
文件。2>&1
表示將標準錯誤(stderr)重定向到標準輸出(stdout),這樣錯誤信息也會被寫入output.log
文件。最后的&
表示將命令放入后臺運行。
nohup command > output.log &
在這種情況下,只有標準輸出會被重定向到output.log
文件,而標準錯誤仍然會顯示在終端上。
nohup command > output.log 2> error.log &
這里,標準輸出會被重定向到output.log
文件,而標準錯誤會被重定向到error.log
文件。
注意:在使用nohup
命令時,建議將輸出文件放在一個安全的位置,以防止意外刪除或覆蓋。