对于常年保持在线服务的服务器系统,通常关机指令不会用到,即便有需要用到,也是重启命令用的会很多。关机常常会在限电、突然长时间停电影响机房供电,业务下线停止运营等情况下。虽然极不常用,但是仍然需要掌握关机命令,以备不时之需。
今天我们主要分享没有UI界面的情况下对关机命令的使用,例如,在Ubuntu系统中,以下是一些常用的关机命令说明:
在Ubuntu中,shutdown命令的语法格式:
- shutdown [OPTIONS...] [TIME] [WALL...]
-
在Ubuntu系统中,有多项shutdown命令参数可以使用。接下来将详细说明:
- mirror@Ubuntu22:~$ 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
-
- Shutdown scheduled for Thu 2023-12-21 16:56:48 CST, use 'shutdown -c' to cancel.
-
- Shutdown scheduled for Thu 2023-12-21 19:30:00 CST, use 'shutdown -c' to cancel.
-
可以在关机前向所有登录用户发送一条自定义的消息。例如,sudo shutdown -h "System will shut down for maintenance"会在关机前通知用户系统将因为维护而关闭。
范例参考:
sudo shutdown -h 19:30 "The system is expected to shut down at 19:30, please prepare in advance "
需要注意的是,shutdown命令都需要超级用户(root)权限,因此在命令前使用了sudo。如果你是以root用户登录的,可以省略sudo。
不同的shutdown关机参数,关机流程并不一样,主要区别是shutdown -h 和shutdown -P
当执行shutdown -H命令时,系统会完成以下操作:
-P选项在这里代表"poweroff"。当执行shutdown -P命令时,系统会按照以下步骤进行:
特别提醒:
希望以上对大家掌握关机方法,有所帮助。