shutdown以一種安全的方式關閉系統。
(1)用法:
用法: shutdown [參數] [時間]
(2)功能:
功能: 系統關機命令,shutdown指令可以關閉所有程序,並依用戶的需要,進行重新開機或關機的動作,所有登陸用戶都可以看到關機信息提示。
原理: shutdown通過通知init進程,要求它改換運行級別來實現。運行級別0用來關閉系統,運行級別6用來重啟系統,運行級別1用來使系統進入執行系統管理任務狀態,如果沒有給出 -h 或 -r 標志時,這是 shutdown 命令的默認工作狀態。
(3)選項參數:
1) -h 將系統關機
2) -r shutdown之后重新啟動
3) -k 只是送出信息給所有用戶,但不會實際關機
4) -f 重啟時跳過磁盤檢測
5) -F 重啟時強制磁盤檢測。
6) -c 取消運行中的 shutdown 進程。不可能為此選項指定 time 參數,但你可以在命令行輸入一條解釋消息來向所有用戶說明。
(一般的shutdown指令可以用按“+”號來進行中斷)
(4)實例:
1)在特定的時間執行關機命令:
shutdown -h now //立即關機 shutdown -h 12:00 //在12:00關機
2)指定5分鍾后關機,同時送出警告信息給登入用戶
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! //系統提醒 This System will be shutdown in 5 minute! //用戶自定義提醒
3)取消關機命令
shutdown -c
4)在特定時間執行關機重啟命令,並取消
[sunmeng@localhost ~]$ su root //必須是root用戶 密碼: [root@localhost sunmeng]# shutdown -r +3 "3分鍾后關機重啟" Shutdown scheduled for 三 2016-06-29 19:47:26 PDT, use 'shutdown -c' to cancel. [root@localhost sunmeng]# Broadcast message from root@localhost.localdomain (Wed 2016-06-29 19:44:26 PDT): 3分鍾后關機重啟 The system is going down for reboot at Wed 2016-06-29 19:47:26 PDT! [root@localhost sunmeng]# 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並不會真正關機,僅僅是給各登錄的用戶發送提醒
[root@localhost sunmeng]# shutdown -k "Warning:Maybe the system will be shutdown." Failed to parse time specification: Warning:Maybe the system will be shutdown. [root@localhost sunmeng]# 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 sunmeng]# 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!
6)快速或慢速重啟(Unbuntu有-f或-F參數,CentOS沒有)
shutdown -f [time] //快速重啟,忽略磁盤檢查 shutdown -F [time] //強制磁盤檢查
(5)其他:
1)永久更改系統時間:
//date命令只能暫時更改系統時間,關機重啟后時間又會回到之前,所以需要將時間寫入bios [root@localhost sunmeng]# date -s "2016-06-30 11:05:10" 2016年 06月 30日 星期四 11:04:30 PDT [root@localhost sunmeng]# clock -w
2)顯示機器的處理器架構:
[root@localhost sunmeng]# arch
x86_64
3)其他關機命令:
init 0 //關機 init 6 //關機重啟 reboot //關機重啟
4)clock與date命令:
//只有超級用戶才能設置硬件時鍾。 [sunmeng@localhost ~]$ su root 密碼: [root@localhost sunmeng]# clock --set --date="05/04/2013 14:30:01" //設置硬件時間為2013年 [root@localhost sunmeng]# clock 2013年05月04日 星期六 14時30分12秒 -0.388214 秒 [root@localhost sunmeng]# date //此時硬件時間為2013,系統時間為2016 2016年 06月 29日 星期三 20:20:36 PDT [root@localhost sunmeng]# clock -s //根據硬件時間設置系統時間 [root@localhost sunmeng]# date 2013年 05月 04日 星期六 14:31:04 PDT [root@localhost sunmeng]# clock 2013年05月04日 星期六 14時31分09秒 -0.101952 秒 //系統時間和硬件時間都為2013年 [root@localhost sunmeng]# date -s "2016-06-30 11:22:10" //設置系統時間為2016年 2016年 06月 30日 星期四 11:22:10 PDT [root@localhost sunmeng]# clock //系統時間為2016年,硬件時間為2013 2013年05月04日 星期六 14時32分13秒 -0.559223 秒 [root@localhost sunmeng]# clock -w //根據系統時間設置硬件時間 [root@localhost sunmeng]# date 2016年 06月 30日 星期四 11:22:51 PDT [root@localhost sunmeng]# clock 2016年06月30日 星期四 11時22分56秒 -0.968643 秒
5)顯示本機shell的信息,也可以更改shell
[sunmeng@localhost ~]$ chsh -l /bin/sh /bin/bash /sbin/nologin /usr/bin/sh /usr/bin/bash /usr/sbin/nologin /bin/tcsh /bin/csh [sunmeng@localhost ~]$ chsh -v chsh,來自 util-linux 2.23.2
每天一個Linux命令的最后一篇,以后還會詳細介紹Linux系統的其他相關知識。
