linux中关机的命令确实不少,下面进行总结和介绍。
1、shutdown
最安全的关机命令,shutdown --help可查看关机参数
| 常用参数 | 作用 |
|---|---|
| -H | 立即关闭计算机 |
| -P | 关闭机器电源 |
| -r | 重启计算机 |
| -h | 相当于–poweroff,被–halt覆盖 |
| -k | 不停止/关闭/重启,只发送警告 |
| -c | 取消已经挂起的关机任务 |
shutdown -h 5 //5分钟后关机
shutdown -h now //立刻关闭计算机
shutdown -h 2:20 //2:20关闭计算机
2、poweroff和halt
这两个命令都是直接关闭计算机,poweroff在关闭系统之后会关闭电源,halt则只关闭系统。
–help可以查看帮助信息,这两个命令的参数一样:
root@kali:~# halt --help
halt [OPTIONS...]
Halt the system.
--help Show this help
--halt Halt the machine
-p --poweroff Switch off the machine
--reboot Reboot the machine
-f --force Force immediate halt/power-off/reboot
-w --wtmp-only Don't halt/power-off/reboot, just write wtmp record
-d --no-wtmp Don't write wtmp record
--no-wall Don't send wall message before halt/power-off/reboot
See the halt(8) man page for details.
root@kali:~# poweroff --help
poweroff [OPTIONS...]
Power off the system.
--help Show this help
--halt Halt the machine
-p --poweroff Switch off the machine
--reboot Reboot the machine
-f --force Force immediate halt/power-off/reboot
-w --wtmp-only Don't halt/power-off/reboot, just write wtmp record
-d --no-wtmp Don't write wtmp record
--no-wall Don't send wall message before halt/power-off/reboot
See the halt(8) man page for details.
3、init
init是所有进程的祖先,他是Linux系统操作中不可缺少的程序之一。发送TERM信号给init会终止所有的用户进程,守护进程等。shutdown 就是使用这种机制。
这个命令的用法有点特别,以数字分级的
root@kali:~# init --help
init [OPTIONS...] {COMMAND}
Send control commands to the init daemon.
--help Show this help
--no-wall Don't send wall message before halt/power-off/reboot
Commands:
0 Power-off the machine
6 Reboot the machine
2, 3, 4, 5 Start runlevelX.target unit
1, s, S Enter rescue mode
q, Q Reload init daemon configuration
u, U Reexecute init daemon

本文总结了Linux系统中的三种关机命令:shutdown、poweroff和halt。shutdown是最安全的关机选项,提供多种参数;poweroff和halt都会关闭计算机,但poweroff会断电,halt仅停止系统。init作为所有进程的祖先,可以通过发送TERM信号来结束进程。
4211

被折叠的 条评论
为什么被折叠?



