本教程操作環(huán)境:linux7.3系統(tǒng)、Dell G3電腦。
linux關機命令shutdown可以實現(xiàn)立刻關機。
(資料圖片)
linux立刻關機的命令有:
shutdown -h now立刻關機(root用戶使用)
halt立刻關機
poweroff立刻關機
如果是通過shutdown命令設置關機的話,可以用shutdown -c命令取消重啟
linux shutdown命令介紹
Linux shutdown命令可以用來進行關機程序,并且在關機以前傳送訊息給所有使用者正在執(zhí)行的程序,shutdown 也可以用來重開機。
使用權限:系統(tǒng)管理者。
語法
shutdown [-t seconds] [-rkhncfF] time [message]
參數說明:
-t seconds : 設定在幾秒鐘之后進行關機程序。-k : 并不會真的關機,只是將警告訊息傳送給所有使用者。-r : 關機后重新開機。-h : 關機后停機。-n : 不采用正常程序來關機,用強迫的方式殺掉所有執(zhí)行中的程序后自行關機。-c : 取消目前已經進行中的關機動作。-f : 關機時,不做 fcsk 動作(檢查 Linux 檔系統(tǒng))。-F : 關機時,強迫進行 fsck 動作。time : 設定關機的時間。message : 傳送給所有使用者的警告訊息。實例
立即關機
# shutdown -h now
指定 10 分鐘后關機
# shutdown -h 10
重新啟動計算機
# shutdown -r now
命令語法:
/sbin/shutdown [-t sec] [-arkhncfFHP] time [warning-message]
命令參數:
參數 | 長參數 | 描敘 |
-a | Use /etc/shutdown.allow. | |
-c | 中斷關機:當執(zhí)行"shutdown -h 12:00"指令時,只要按+鍵就可以中斷關機的指令 | |
-f | 重新啟動時不進行磁盤檢測(fsck) | |
-F | 重新啟動時進行磁盤檢測(fsck) | |
-h | 關閉電源 | |
-k | 模擬關機(不是真的關機),只是向登錄者發(fā)送警告信息出去! | |
-n | 不調用init進程進行關機,而是強行關機 | |
-r | 關閉系統(tǒng)然后重新啟動,類似于Windows平臺restart | |
-t | 延遲關機的時間 | |
-w | 僅做測試,并不真的將系統(tǒng)重新開機,只會把重開機的數據寫入/var/log目錄下的wtmp記錄文件 | |
--help | 顯示命令在線幫助 |
示例:1:馬上關閉Linux系統(tǒng),其中 now 相當于時間為 0 的狀態(tài)示例:
# shutdown -h now
2:系統(tǒng)2分鐘后重新啟動,其中+m表示幾分鐘后關機或開機。
[root@db-server ~]# shutdown -r +2
3:設置系統(tǒng)在那個時間點關機
# shutdown -h 12:30
或后臺執(zhí)行
# shutdown -h 12:30 &
最好是使用命令&將關機命令至于后臺處理。不影響當前其它操作。
設置多久時間后執(zhí)行shutdown命令。時間參數有hh:mm或+m兩種模式。hh:mm格式表示在幾點幾分執(zhí)行shutdown命令。例如 “shutdown 10:45”表示將在10:45執(zhí)行shutdown.+m表示m分鐘后執(zhí)行shutdown.比較特別的用法是以now表示立即執(zhí)行shutdown. 值得注意的是這部分參數不能省略。另外,需要注意如果現(xiàn)在已經22:30,你執(zhí)行了shutdown -h 22:00 & 那么第二天才會關機。
4:查看后臺是否執(zhí)行shutdown命令
# jobs[1]+ Running shutdown -h 08:00 &
5:取消shutdown命令執(zhí)行
執(zhí)行了下面命令讓Linux在12:30關機,但是如果發(fā)現(xiàn)這個時間點不合適,那么可以使用CTRL+C取消。
# shutdown -h 12:30Shutdown cancelled.
也可以在另外一個命令窗口執(zhí)行下面命令
# shutdown -c
6:向所有登錄的用戶發(fā)出信息
# 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 nowBroadcast message from root (pts/1) (Sat Jan 10 20:23:59 2015): The system is going down for reboot NOW!
8:在多少秒后關閉系統(tǒng)并給用戶發(fā)送提示信息
[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!
推薦學習:Linux視頻教程
以上就是linux關機命令shutdown可以實現(xiàn)立刻關機嗎的詳細內容,更多請關注php中文網其它相關文章!