立即关闭系统

要关闭 Linux 操作系统,请使用带参数 -h 的关闭命令。
其中:我使用“现在”一词来立即关闭系统。

语法 :

# shutdown [Option] [Time]
# shutdown -h now          ### Immediate Shutdown a Linux System

关闭系统

要关闭 Linux 系统,只需使用带参数 -P 的关机命令。
其中:我将在 1 分钟后关闭系统电源。

# shutdown -P +1        ### Power Off the System after 1 Minute
Broadcast message from root@onitroad.com
	(/dev/pts/0) at 9:10 ...
The system is going down for power off in 1 minute!

“halt”和“poweroff”命令之间的区别

其中:我们可能会认为这就是 Halt 和 Power Off 之间的区别。
Halt 和 Power Off 之间的确切区别在于 Halt 仅操作系统关闭,但在关闭电源的情况下,操作系统关闭,然后系统指示 ACPI 向电源单元发送信号以关闭系统电源。
ACPI 代表高级配置电源接口。

有关 Linux 关机的更多帮助,我们可以使用以下命令。

# shutdown --help   # For more Help on Shutdown Command
Usage: shutdown [OPTION]... TIME [MESSAGE]
Bring the system down.
Options:
  -r                          reboot after shutdown
  -h                          halt or power off after shutdown
  -H                          halt after shutdown (implies -h)
  -P                          power off after shutdown (implies -h)
  -c                          cancel a running shutdown
  -k                          only send warnings, don't shutdown
  -q, --quiet                 reduce output to errors only
  -v, --verbose               increase output to include informational messages
      --help                  display this help and exit
      --version               output version information and exit

一段时间后关闭系统

我们可以以分钟为单位设置时间,之后系统将关闭。
例如,如果我们想在 1 分钟后关闭系统,则使用关闭命令将时间设置为 +1.
参考下面的命令。

# shutdown -h +1           ### Shutdown the System after 1 Minute
Broadcast message from root@localhost.localdomain
	(/dev/pts/1) at 20:19 ...
The system is going down for halt in 1 minute!

发送假关机警告消息

带参数 -k 的关机命令只会向用户发送假关机警告,但不会关机。

# shutdown -k +1 "System is going to Shutdown"        ### Send a fake Shutdown Warning

Broadcast message from root@onitroad.com
	(/dev/pts/0) at 9:07 ...
The system is going down for maintenance in 1 minute!
System is going to Shutdown

“halt”命令

我们还可以使用其他命令关闭系统。
例如,可以使用halt 命令关闭系统。

# halt        ### Shutdown a Linux System
on it road .com

重新启动系统

要重新启动 Linux 系统,请使用带参数 -r 的 shutdown 命令。
这里我使用“now”这个词来立即重启系统。

# shutdown -r now         ### Restart a System Immediately

我们可以以分钟为单位设置时间,之后系统将重新启动。
其中:我想在 2 分钟后重新启动系统,因此使用 Linux 关闭命令将时间设置为 +2.

# shutdown -r +2         ### Restart the system after 2 Minutes
Broadcast message from root@localhost.localdomain
	(/dev/pts/1) at 20:21 ...
The system is going down for reboot in 2 minutes!
Linux 中的“shutdown”命令示例

重启系统前广播消息

如果我们想在重新启动系统之前向用户发送一些消息,那么我们可以使用 Linux 关机命令来实现。
参考下面的命令。

# shutdown -r +10 "System is going to Reboot"
Broadcast message from root@onitroad.com
	(/dev/pts/0) at 8:45 ...
The system is going down for reboot in 10 minutes!
System is going to Reboot

关闭系统前广播消息

如果你想在关闭系统之前向用户发送一些消息,那么你可以使用 Linux shutdown 命令来实现。
参考下面的命令。
该消息以红色突出显示。

# shutdown -h +10 "System is going to Shutdown"  # Send a Message to user before Shutdown the System
Broadcast message from root@onitroad.com
	(/dev/pts/0) at 8:43 ...
The system is going down for halt in 10 minutes!
System is going to Shutdown

介绍

在本文中,我们将通过示例学习 Linux 关机命令。
shutdown 命令用于停止/关闭、重启 Linux 操作系统。

当以 root 身份正确输入关闭并使用有效的时间参数时,它会执行以下操作。

  • 通知所有用户系统即将宕机
  • 阻止其他登录
  • 通知所有正在运行的程序,以便它们可以关闭/保存文件并正常退出
  • 通知 init 改变运行级别
  • 嘘!告诉 init 带我们到 X 级

“poweroff”命令

我们也可以使用 poweroff 命令关闭系统。

# poweroff           ### Shutdown the System
# poweroff -f        ### Shutdown the System Forcefully

“reboot”命令

我们还可以使用 reboot 命令重新启动 Linux 操作系统。

# reboot            ### Restart the System
# reboot -f           ### Restart the System Forcefully

取消关机命令

带参数 -c 的关机命令可用于取消正在运行的关机。

# shutdown -c         ### Cancel a Running Shutdown
日期:2020-09-17 00:14:30 来源:oir作者:oir