shutdown命令用来系统关机命令。shutdown指令可以关闭所有程序,并依用户的需要,进行重新开机或关机的动作。
语法
shutdown(选项)(参数)
选项
-c:当执行“shutdown -h 11:50”指令时,只要按+键就可以中断关机的指令; -f:重新启动时不执行fsck; -F:重新启动时执行fsck; -h:将系统关机; -k:只是送出信息给所有用户,但不会实际关机; -n:不调用init程序进行关机,而由shutdown自己进行; -r:shutdown之后重新启动; -t<秒数>:送出警告信息和删除信息之间要延迟多少秒。
参数
[时间]:设置多久时间后执行shutdown指令;
[警告信息]:要传送给所有登入用户的信息。
实例
指定现在立即关机:
shutdown -h now
指定5分钟后关机,同时送出警告信息给登入用户:
shutdown +5 "System will shutdown after 5 minutes"
详解:
1:马上关闭Linux系统,其中 now 相当于时间为 0 的状态
[root@db-server ~]# shutdown -h now Broadcast message from root (pts/1) (Sat Jan 10 18:51:34 2015): The system is going down for system halt NOW!
2:系统2分钟后重新启动,其中+m表示几分钟后关机或开机。
[root@db-server ~]# shutdown -r +2 Broadcast message from root (pts/2) (Sat Jan 10 19:56:00 2015): The system is going DOWN for reboot in 2 minutes!
3:设置系统在那个时间点关机
[root@db-server ~]# shutdown -h 12:30
或
[root@db-server ~]# shutdown -h 12:30 & [1] 4578
最好是使用命令&将关机命令至于后台处理。不影响当前其它操作。
设置多久时间后执行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命令取消息
如下所示,执行了下面命令让Linux在12:30关机,但是如果发现这个时间点不合适,那么可以使用CTRL+C取消
[root@db-server ~]# shutdown -h 12:30 Shutdown cancelled. [root@db-server ~]#
也可以在另外一个命令窗口执行下面命令
[root@db-server ~]# shutdown -c
5:向所有登录的用户发出信息
[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.
6:重新启动时不进行磁盘检测
[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!
7:在多少秒后关闭系统并给用户发送提示信息
[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!
重启命令:
1、reboot 2、shutdown -r now 立刻重启(root用户使用) 3、shutdown -r 10 过10分钟自动重启(root用户使用) 4、shutdown -r 20:35 在时间为20:35时候重启(root用户使用)
关机命令:
1、halt 立刻关机 2、poweroff 立刻关机 3、shutdown -h now 立刻关机(root用户使用) 4、shutdown -h 10 10分钟后自动关机优质内容筛选与推荐>>
1、我们生活在一个被水产的年代
2、面试英语一
3、Date类
4、第一章 你要做什么?
5、数据挖掘系列