在 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
命令時,建議使用絕對路徑來指定命令和文件,以避免因環境變量或當前工作目錄改變而導致的問題。