sync
將記憶體緩衝區資料強制寫入硬碟。雖然現代關機指令多內建 sync,但習慣在關機前手動執行幾次 sync,可最大程度保障資料不遺失。
shutdown [選項] 時間 [訊息]
| 選項 | 功能 |
|---|---|
-h | 關機(halt 或 poweroff) |
-r | 重啟 |
-H | 僅 halt(不切斷電源) |
-P | 關機並切斷電源 |
-k | 僅發送警告訊息,不實際關機 |
-c | 取消已排程的關機 |
now 或 +0:立即執行+20:20 分鐘後20:30:今日 20:30 執行shutdown -h now # 立即關機
shutdown -r +10 "10分鐘後重啟" # 10分鐘後重啟並通知所有使用者
shutdown -c # 取消排程
shutdown 透過傳送訊號給 init(PID 1),要求切換 Runlevel:
| 指令 | 功能 | 備註 |
|---|---|---|
reboot | 重啟系統 | 相當於 shutdown -r now |
halt | 停止系統(不切電) | 相當於 shutdown -h now |
poweroff | 關機並切斷電源 | 相當於 shutdown -P now |
-f:強制執行,不經由 shutdown(不建議常用,可能造成資料遺失)-w:僅寫入 /var/log/wtmp 記錄,不實際關機/重啟--verbose:顯示詳細執行資訊init 0 # 關機
init 6 # 重啟
適用於 SysVinit 系統。現代 systemd 系統建議改用 systemctl poweroff / systemctl reboot。
| systemd 指令 | 對應傳統指令 |
|---|---|
systemctl poweroff | shutdown -h now / poweroff |
systemctl reboot | shutdown -r now / reboot |
systemctl halt | halt |
systemctl suspend | 暫停(待機到記憶體) |
systemctl hibernate | 休眠(存檔到硬碟) |
shutdown 排程關機,給使用者緩衝時間sync; sync; sync 確保資料落盤-f 強制參數systemctl 系列指令