Linux命令之nohup 和 重定向

用途:使運行的程序忽略SIGHUP。

語法:nohup Command [ Arg ... ] [ & ]
描述:nohup 命令運行由 Command 參數和任何相關的 Arg 參數指定的命令,忽略所有掛斷(SIGHUP)信號。在註銷後使用 nohup 命令運行後臺中的程序。要運行後臺中的 nohup 命令,添加 & ( 表示“and”的符號)到命令的尾部。

那麼如果需要重定向該怎麼辦?

nohup ./start-dishi.sh > FILE  & 即可

nohup的man文檔中說明了:

  • If standard input is a terminal, redirect it from an unreadable file.
  • If standard output is a terminal, append output to 'nohup.out' if possible, '$HOME/nohup.out' otherwise.
  • If standard error is a terminal, redirect it to standard output.
  • To save output to FILE, use 'nohup COMMAND > FILE'.

就是說 默認會把標準錯誤 重定向到標準輸出。標準輸出默認是 nohup.out, 可以加上‘ > FILE’ 重定向到自定義文件。

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章