? ? In Linux, there are at least 5 commands related to shutdown and restart,shutdown, Halt, Poweroff, reboot, and Init. The individual commands function as follows:
| Command |
Description |
| Shutdown |
Can be used to shut down and restart the computer. Support Timing and notifications |
| Halt |
Stop the system |
| Poweroff |
Shutdown |
| Reboot |
Rebooting the system |
| Init |
Init 0: Shutdown, init 6: Restart |
Shutdown
Common usage is as follows:
shutdown [选项] 时间 [消息]
The common options are as follows
| Options |
Description |
| -R |
Restart the system after it is stopped |
| -H |
Shut down after the system stops |
| -C |
Cancel shutdown |
| -K |
Sends a warning message and disables login. Off is not really to shut down the machine |
| -P |
After the system is stopped and power is turned off |
Halt
Common usage is as follows:
halt [选项]
The common options are as follows
| Options |
Description |
| -F,--force |
Enforces halt or reboot without calling shutdown |
| -P,--poweroff |
Equivalent to Poweroff |
| -W,--wtmp-only |
Writes shutdown records to the/var/log/wtmp file only, without actually shutting down or restarting the computer |
| -D,--no-wtmp |
Do not write shutdown records to the Wtmp file |
Poweroff
Common usage is as follows:
poweroff [选项]
The common options are as follows
| Options |
Description |
| -P,--poweroff |
Shut down the machine |
| --reboot |
Rebooting the system |
| -F,--force |
Force shut down the machine |
| -W,--wtmp-only |
Writes shutdown records to the Wtmp file only, without shutting down or restarting the computer |
| -D,--no-wtmp |
Do not write shutdown records to the Wtmp file |
Reboot
Common usage is as follows:
reboot [选项]
The common options are as follows
| Options |
Description |
| -P,--poweroff |
Shut down the machine |
| --reboot |
Restarting the machine |
| -F,--force |
Forcing the machine to restart |
| -W,--wtmp-only |
Only the restart record is written to the wtmp file without shutting down or restarting |
| -D,--no-wtmp |
Do not write the restart record to the Wtmp file |
Init
Common usage is as follows:
reboot [选项] [命令]
The common options are as follows
| Options |
Description |
| --help |
Display Help information |
| --no-wall |
Do not send messages until shutdown and restart |
The common commands are as follows:
| Command |
Description |
| 0 |
Shut down the machine |
| 6 |
Restarting the machine |
Usage examples
# 立即关机[[email protected] system]# shutdown -h now# 立即重启[[email protected] system]# shutdown -r now# 在指定时间重启[[email protected] system]# shutdown -r 19:30# 在3分钟后关机[[email protected] system]# shutdown -h +3# 关机并关闭电源[[email protected] system]# halt -p# 关机但不写记录[[email protected] system]# halt -d# 测试关机[[email protected] system]# halt -w# 重启系统[[email protected] system]# reboot# 关机并关闭电源[[email protected] system]# poweroff# 重启[[email protected] system]# init 6# 关机[[email protected] system]# init 0
In the above command, when using man to view the help, you will find halt, Poweroff, reboot are the same, the other three commands is a program, as follows:
Shutdown and restart summary
- Shutdown-r is used to restart, equivalent to reboot
- Shutdown-h-P is used to shut down the system and power off, equivalent to Poweroff
- Poweroff equivalent to Halt-p
- The shutdown-h is used to shut down the system, but not power off, equivalent to halt
- The main difference between shutdown and Reboot/halt is that shutdown sends a shutdown or restart notification message to the user who is logged on to the system
- Shutdown-k only for test shutdown
- Init relies on the native init system, in which case the shutdown has a runlevel of 0 and a restart of 6
This article is posted on the subscription number, such as your friends like my article, you can also follow my subscription number: Woaitest, or scan the following QR code to add attention:
Linux Basic Tutorial 41-system shutdown and restart