linux常用命令:shutdown 命令
shutdown以一種安全的方式關(guān)閉系統(tǒng)。
1.命令格式:
shutdown [參數(shù)] [時(shí)間]
2.命令功能:
功能: 系統(tǒng)關(guān)機(jī)命令,shutdown指令可以關(guān)閉所有程序,并依用戶的需要,進(jìn)行重新開機(jī)或關(guān)機(jī)的動(dòng)作,所有登陸用戶都可以看到關(guān)機(jī)信息提示。
原理: shutdown通過通知init進(jìn)程linux常用命令,要求它改換運(yùn)行級(jí)別來實(shí)現(xiàn)。運(yùn)行級(jí)別0用來關(guān)閉系統(tǒng),運(yùn)行級(jí)別6用來重啟系統(tǒng)linux常用命令,運(yùn)行級(jí)別1用來使系統(tǒng)進(jìn)入執(zhí)行系統(tǒng)管理任務(wù)狀態(tài),如果沒有給出 -h 或 -r 標(biāo)志時(shí),這是 shutdown 命令的默認(rèn)工作狀態(tài)。
3.選項(xiàng)參數(shù):
1) -h將系統(tǒng)關(guān)機(jī)
2)-rshutdown之后重新啟動(dòng)
3) -k只是送出信息給所有用戶,但不會(huì)實(shí)際關(guān)機(jī)
4)-f重啟時(shí)跳過磁盤檢測
5)-F重啟時(shí)強(qiáng)制磁盤檢測。
6) -c取消運(yùn)行中的 shutdown 進(jìn)程。不可能為此選項(xiàng)指定 time 參數(shù),但你可以在命令行輸入一條解釋消息來向所有用戶說明。
(一般的shutdown指令可以用按“+”號(hào)來進(jìn)行中斷)
4.使用實(shí)例:
1)在特定的時(shí)間執(zhí)行關(guān)機(jī)命令:
shutdown -h now //立即關(guān)機(jī)
shutdown -h 12:00 //在12:00關(guān)機(jī)
2)指定5分鐘后關(guān)機(jī),同時(shí)送出警告信息給登入用戶
root@Unbuntu:/home/sunjimeng# shutdown +5 "This System will be shutdown in 5 minute!"
來自sunjimeng@Unbuntu的廣播信息
(/dev/pts/6) 于 10:38 ...
The system is going down for maintenance in 5 minutes! //系統(tǒng)提醒
This System will be shutdown in 5 minute! //用戶自定義提醒
3)取消關(guān)機(jī)命令
shutdown -c
4)在特定時(shí)間執(zhí)行關(guān)機(jī)重啟命令,并取消
[xiong@localhost ~]$ su root //必須是root用戶
密碼:
[root@localhost xiong]# shutdown -r +3 "3分鐘后關(guān)機(jī)重啟"
Shutdown scheduled for 三 2016-06-29 19:47:26 PDT, use 'shutdown -c' to cancel.
[root@localhost xiong]#
Broadcast message from root@localhost.localdomain (Wed 2016-06-29 19:44:26 PDT):
3分鐘后關(guān)機(jī)重啟
The system is going down for reboot at Wed 2016-06-29 19:47:26 PDT!
[root@localhost xiong]# shutdown -c
Broadcast message from root@localhost.localdomain (Wed 2016-06-29 19:44:50 PDT):
The system shutdown has been cancelled at Wed 2016-06-29 19:45:50 PDT!
5)shutdown -k并不會(huì)真正關(guān)機(jī),僅僅是給各登錄的用戶發(fā)送提醒
[root@localhost xiong]# shutdown -k "Warning:Maybe the system will be shutdown."
Failed to parse time specification: Warning:Maybe the system will be shutdown.
[root@localhost xiong]# shutdown -k 5 "Warning:Maybe the system will be shutdown."
Shutdown scheduled for 三 2016-06-29 19:53:56 PDT, use 'shutdown -c' to cancel.
[root@localhost xiong]#
Broadcast message from root@localhost.localdomain (Wed 2016-06-29 19:48:56 PDT):
Warning:Maybe the system will be shutdown.
The system is going down for power-off at Wed 2016-06-29 19:53:56 PDT!