Linux学习之路(三)关机命令总结

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

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
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值