Linux命令之shutdown

1.shutdown介绍

linux命令shutdown主要用来重启、关闭服务器。

2.shutdown用法

shutdown [参数]

shutdown常用参数
参数说明
-c取消即将执行的关机程序
-k

仅仅向每个登录用户发出警告信息,并不真正关机

-h关机(halt)
-H关机(halt)
-P关机(poweroff)
-r重启(reboot)
--help

shutdown帮助信息

3.实例

3.1.立即关机

命令:

shutdown -H now

OR

shutdown -h now

OR

shutdown -P now

OR

init 0

OR

poweroff

3.2.立即重启

命令:

shutdown -r now

OR

reboot

OR

init 6

3.3.30分钟后关机,并给出提示信息

命令:

shutdown -h +30 "The system will poweroff"

[root@rhel77 ~]# shutdown -h +30 "The system will poweroff"
Shutdown scheduled for Tue 2023-06-13 11:33:48 CST, use 'shutdown -c' to cancel.
[root@rhel77 ~]# 

使用shutdown -c可以取消上述动作

[root@rhel77 ~]# shutdown -h +30 "The system will poweroff"
Shutdown scheduled for Tue 2023-06-13 11:33:48 CST, use 'shutdown -c' to cancel.
[root@rhel77 ~]# 
[root@rhel77 ~]# shutdown -c

Broadcast message from root@rhel77 (Tue 2023-06-13 11:04:30 CST):

The system shutdown has been cancelled at Tue 2023-06-13 11:05:30 CST!

[root@rhel77 ~]# 

3.4.仅发出警告,系统不会关机

命令:

shutdown -k now "testing,haha"

[root@rhel77 ~]# shutdown -k now 'testing,haha'
[root@rhel77 ~]# 

3.5.查看shutdown帮助信息

命令:

shutdown --help

[root@rhel77 ~]# shutdown --help
shutdown [OPTIONS...] [TIME] [WALL...]

Shut down the system.

     --help      Show this help
  -H --halt      Halt the machine
  -P --poweroff  Power-off the machine
  -r --reboot    Reboot the machine
  -h             Equivalent to --poweroff, overridden by --halt
  -k             Don't halt/power-off/reboot, just send warnings
     --no-wall   Don't send wall message before halt/power-off/reboot
  -c             Cancel a pending shutdown
[root@rhel77 ~]# 

3.6.shutdown -h now、shutdown -H now、shutdown -P now的区别

1.shutdown -h now则根据系统的默认设置来选择是否关闭电源

2.shutdown -H now是关机操作,系统停止运行,但并未关闭电源   --可以vmware构建的虚机中运行此命令,进行观察,不建议使用此命令

[root@rhel77 ~]# shutdown -H now
Connection closing...Socket close.

Connection closed by foreign host.

Disconnected from remote host(192.168.10.137:22) at 11:13:49.

Type `help' to learn how to use Xshell prompt.
[C:\~]$ 

虚机关机现象截图:

-->

 -->

只能在VMware界面,进行"再次"关机动作

3.shutdown -P now是关闭电源操作

Logo

旨在为数千万中国开发者提供一个无缝且高效的云端环境,以支持学习、使用和贡献开源项目。

更多推荐