首頁·終端機命令

nohup

行程與系統

用法

nohup <command> [args] &

讓命令忽略掛斷訊號,這樣登出後它還在跑;它並不會幫你放到背景,`&` 得自己加,輸出會悄悄堆在 ./nohup.out 裡。

常用選項

選項含義
&You add this yourself: nohup alone does not put the command in the background.
> out.log 2>&1Send output somewhere other than the default ./nohup.out.
< /dev/nullDetach stdin as well, so the command cannot stall waiting for input.

範例

nohup ./server.sh > server.log 2>&1 &

Start the server so it survives logout, with its own log file.

nohup make -j4 &

Run a long build that keeps going after you disconnect; output lands in nohup.out.

看什麼在跑、什麼在吃機器。先弄清是什麼,再決定殺不殺。

怎麼看

  • 方括號 [ ] 表示這部分可以不寫。
  • 省略號 … 表示可以寫多個。
  • 選項區分大小寫——有些命令裡 -r 和 -R 不是一回事。

常見問題

Q. nohup 是做什麼的?

讓命令忽略掛斷訊號,這樣登出後它還在跑;它並不會幫你放到背景,`&` 得自己加,輸出會悄悄堆在 ./nohup.out 裡。

Q. 怎麼寫?

nohup <command> [args] & —— 方括號表示可以省略的部分。

Q. 值得記的選項有幾個?

這裡列了 3 個,完整列表在 man nohup。這條命令屬於行程與系統。

相關命令

man 手冊: man nohup