Linux 各关机命令详解

文章
林里克斯

linux 下一些常用的 关机/重启 命令有 shutdownhaltpoweroffreboot、及 init,其中 shutdownhaltpoweroff 专注关机,rebootinit 既可以实现关机也可以实现关机后再启动。

Linux 各关机命令详解


实验平台:CentOS Linux release 7.9.2009



一、shutdown


1.shutdown 命令详解

# shutdown --help

     --help      #打印 help 信息
  -H --halt      #一分钟后关机,使用 halt
  -P --poweroff  #一分钟后关机,使用 power-off
  -r --reboot    #一分钟后重启,使用 reboot
  -h             #相当于 --poweroff
  -k             #不真正执行 halt/power-off/reboot, 给每个用户发送消息
     --no-wall   #在执行 halt/power-off/reboot 不发送消息给用户
  -c             #取消定时的关机操作
#是 `systemctl` 的软连

2.操作示例

# shutdown -h 23:00     #定时 23:00 关机
# shutdown -h now       #立刻关机
# shutdown -h +30       #定时 30 分钟后关机
# shutdown -h +15 "Shut down after 15 minutes"  #定时 15 分钟后关机,并发送消息给用户

二、halt


1.halt 命令详解

最简单的关机命令,执行过程中会杀掉所有应用进程,并在文件系统写操作完成之后就会停止内核的运行。调用 shutdown -h 来执行。halt 通知硬件来停止所有的 CPU 功能,但是仍然保持通电。你可以用它使系统处于低层维护状态

#halt --help

     --help      #打印 help 信息
     --halt      #关机
  -p --poweroff  #关机,使用 power-off
     --reboot    #重启机器
  -f --force     #强制执行 halt/power-off/reboot
  -w --wtmp-only #不执行 halt/power-off/reboot,只是写 wtmp 记录
  -d --no-wtmp   #不写入 wtmp 记录
     --no-wall   #在执行 halt/power-off/reboot 不发送消息给用户
#是 `systemctl` 的软连

三、reboot


reboot 关机使用的是 halt,关闭计算器后会再启动计算机.是 systemctl 的软连


四、poweroff


halt 一样是 systemctl 的软连,poweroff 会发送一个 ACPI 信号来通知系统关机

$ ls -l /usr/sbin/poweroff 
lrwxrwxrwx. 1 root root 16 Nov 30 20:21 /usr/sbin/poweroff -> ../bin/systemctl
$ ls -l /usr/sbin/halt 
lrwxrwxrwx. 1 root root 16 Nov 30 20:21 /usr/sbin/halt -> ../bin/systemctl

五、init


init 调用运行级别,具体命令详解可参考 --> Linux 之 init 命令详解


Over~

版权协议须知!

本篇文章来源于 Uambiguous ,如本文章侵犯到任何版权问题,请立即告知本站,本站将及时予与删除并致以最深的歉意

799 0 2020-12-14


分享:
icon_mrgreen.gificon_neutral.gificon_twisted.gificon_arrow.gificon_eek.gificon_smile.gificon_confused.gificon_cool.gificon_evil.gificon_biggrin.gificon_idea.gificon_redface.gificon_razz.gificon_rolleyes.gificon_wink.gificon_cry.gificon_surprised.gificon_lol.gificon_mad.gificon_sad.gificon_exclaim.gificon_question.gif
博主卡片
林里克斯 博主大人
一个致力于Linux的运维平台
运维时间
搭建这个平台,只为分享及记载自己所遇之事和难题。

现在时间 2024-05-18

今日天气
站点统计
  • 文章总数:240篇
  • 分类总数:29个
  • 评论总数:10条
  • 本站总访问量 222967 次

@奥奥

@Wong arrhenius 牛比

@MakerFace 厉害了!