在 CentOS 系統中,使用 nohup
命令運行程序時,默認的日志文件名是 nohup.out
。如果你想修改這個日志文件的名字,可以通過重定向輸出到指定的文件來實現。
以下是一個示例,展示了如何將 nohup
命令的輸出重定向到一個自定義的日志文件:
nohup your_command > custom_log_file.log 2>&1 &
解釋:
your_command
是你想運行的命令。>
將標準輸出(stdout)重定向到 custom_log_file.log
。2>&1
將標準錯誤(stderr)重定向到標準輸出(stdout),這樣標準錯誤也會被寫入到 custom_log_file.log
。&
將命令放到后臺運行。例如,如果你想運行一個名為 my_script.sh
的腳本,并將日志輸出到 my_custom_log.log
,可以這樣做:
nohup ./my_script.sh > my_custom_log.log 2>&1 &
這樣,所有的輸出(包括標準輸出和標準錯誤)都會被寫入到 my_custom_log.log
文件中,而不是默認的 nohup.out
文件。