命令語法:
/sbin/shutdown [-t sec] [-arkhncfFHP] time [warning-message]
命令參數:
參數 |
長參數 |
描敘 |
-a |
Use /etc/shutdown.allow. |
|
-c |
中斷關機:當執行"shutdown -h 12:00"指令時,只要按+鍵就可以中斷關機的指令 |
|
-f |
重新啟動時不進行磁盤檢測(fsck) |
|
-F |
重新啟動時進行磁盤檢測(fsck) |
|
-h |
關閉電源 |
|
-k |
模擬關機(不是真的關機),只是向登錄者發送警告信息出去! |
|
-n |
不調用init進程進行關機,而是強行關機 |
|
-r |
關閉系統然后重新啟動,類似於Windows平台restart |
|
-t |
延遲關機的時間 |
|
-w |
僅做測試,並不真的將系統重新開機,只會把重開機的數據寫入/var/log目錄下的wtmp記錄文件 |
|
--help |
顯示命令在線幫助 |
示例:
1:馬上關閉Linux系統,其中 now 相當於時間為 0 的狀態
[root@db-server ~]# shutdown -h now
2:系統2分鍾后重新啟動,其中+m表示幾分鍾后關機或開機。
[root@db-server ~]# shutdown -r +2
3:設置系統在那個時間點關機
[root@db-server ~]# shutdown -h 12:30
或后台執行
[root@db-server ~]# shutdown -h 12:30 &
最好是使用命令&將關機命令至於后台處理。不影響當前其它操作。
設置多久時間后執行shutdown命令。時間參數有hh:mm或+m兩種模式。hh:mm格式表示在幾點幾分執行shutdown命令。例如 “shutdown 10:45”表示將在10:45執行shutdown.+m表示m分鍾后執行shutdown.比較特別的用法是以now表示立即執行shutdown. 值得注意的是這部分參數不能省略。另外,需要注意如果現在已經22:30,你執行了shutdown -h 22:00 & 那么第二天才會關機。
4:查看后台是否執行shutdown命令
[root@db-server ~]# jobs
[1]+ Running shutdown -h 08:00 &
5:取消shutdown命令執行
執行了下面命令讓Linux在12:30關機,但是如果發現這個時間點不合適,那么可以使用CTRL+C取消。
[root@db-server ~]# shutdown -h 12:30
Shutdown cancelled.
[root@db-server ~]#
也可以在另外一個命令窗口執行下面命令
[root@db-server ~]# shutdown -c
6:向所有登錄的用戶發出信息
[root@db-server ~]# shutdown -k "now"
Broadcast message from root (pts/2) (Sat Jan 10 20:09:14 2015):
The system is going down to maintenance mode NOW!
Shutdown cancelled.
另外登錄的會話窗口會收到如下信息
[root@db-server ~]#
[root@db-server ~]#
Broadcast message from root (pts/2) (Sat Jan 10 20:11:34 2015):
The system is going down to maintenance mode NOW!
一般使用下面語法,如下所示
[root@db-server ~]# shutdown -k now "The Server will shutdown now
Broadcast message from root (pts/1) (Sat Jan 10 20:14:54 2015):
The Server will shutdown now
The system is going down to maintenance mode NOW!
Shutdown cancelled.
7:重新啟動時不進行磁盤檢測
[root@db-server ~]# shutdown -fr now
Broadcast message from root (pts/1) (Sat Jan 10 20:23:59 2015):
The system is going down for reboot NOW!
8:在多少秒后關閉系統並給用戶發送提示信息
[root@db-server ~]# shutdown -t 10 -h now "System will shutdown 10 sencond later"
Broadcast message from root (pts/1) (Sat Jan 10 20:33:36 2015):
System will shutdown 10 sencond later
The system is going down for system halt NOW!