<section id=”nice” data-tool=”mdnice编辑器” data-website=”https://www.mdnice.com” style=”font-size: 16px; color: black; padding: 0 10px; line-height: 1.6; word-spacing: 0px; letter-spacing: 0px; word-break: break-word; word-wrap: break-word; text-align: left; font-family: Optima-Regular, Optima, PingFangSC-light, PingFangTC-light, ‘PingFang SC’, Cambria, Cochin, Georgia, Times, ‘Times New Roman’, serif;”><p data-tool=”mdnice编辑器” style=”font-size: 16px; padding-top: 8px; padding-bottom: 8px; margin: 0 0 20px; padding: 0; line-height: 1.8em; color: #3a3a3a;”>Linux零碎关机命令有哪些呢?良许教程网为您解答!相熟linux的敌人应该晓得咱们在linux零碎中罕用到的关机命令有:shutdown
、halt
、poweroff
、init
;重启命令有:reboot
。上面本文就次要介绍一些罕用的关机命令以及各种关机命令之间的区别和具体用法。
以下是比拟罕用的一些关机命令
1、halt
立即关机
2、poweroff
立即关机
3、shutdown -h now
立即关机(root用户应用)
4、shutdown -h
10 10分钟后自动关机
注:如果是通过shutdown
命令设置关机的话,能够用shutdown -c
命令勾销重启。</p>
<p data-tool=”mdnice编辑器” style=”font-size: 16px; padding-top: 8px; padding-bottom: 8px; margin: 0 0 20px; padding: 0; line-height: 1.8em; color: #3a3a3a;”>重启命令:</p>
<pre class=”custom” data-tool=”mdnice编辑器” style=”margin-top: 10px; margin-bottom: 10px;”>2、shutdown -r now 立即重启(root用户应用)
</pre>
3、shutdown -r 10 过10分钟主动重启(root用户应用)
4、shutdown -r 20:35 在工夫为20:35时候重启(root用户应用)
<p data-tool=”mdnice编辑器” style=”font-size: 16px; padding-top: 8px; padding-bottom: 8px; margin: 0 0 20px; padding: 0; line-height: 1.8em; color: #3a3a3a;”>注:如果是通过shutdown
命令设置重启的话,能够用shutdown -c
命令勾销重启。
上面咱们追随良许教程网的小编来看看linux的这些具体的关机命令之间的区别以及各自的用法
1.shutdown
平安的关机命令
对于shutdown命令,它是大家都举荐的一个平安的命令,通过参数-h或-r的配合来实现关机或重启。不过在linux零碎中只有领有root权限才能够应用这个命令。所以,尽管大家都举荐用这个命令,然而这个命令用起来真的不太不便:想要用这个命令吗?先去取得root权限吧。shutdown执行关机,是送信号给init,要求它扭转运行级别,以此来关机。关机或重启实际上是运行级别的调整,所以咱们也能够用init间接调整运行级别来进行关机或重启。应用这个命令时,机器立刻关机或重启。它也须要root权限。
那么为什么说shutdown命令是平安地将零碎关机呢?
<img src=”https://pic.downk.cc/item/5fe1dcd63ffa7d37b37c87a5.jpg” alt=”linux零碎” style=”margin: 0 auto; max-width: 100%; width: 100%; border-radius: 5px; display: block; margin-bottom: 15px; height: auto;”>
理论中有些用户会应用间接断掉电源的形式来敞开linux,这是非常危险的。因为linux与windows不同,其后盾运行着许多过程,所以强制关机可能会导致过程的数据失落使零碎处于不稳固的状态。甚至在有的零碎中会损坏硬件设施。而在零碎关机前应用shutdown命令,系统管理员会告诉所有登录的用户零碎将要敞开。并且login指令会被解冻,即新的用户不能再登录。间接关机或者提早肯定的工夫才关机都是可能的,还有可能是重启。这是由所有过程〔process〕都会收到零碎所送达的信号〔signal〕决定的。
shutdown执行它的工作是送信号〔signal〕给init程序,要求它扭转 runlevel。runlevel 0 被用来停机〔halt〕,runlevel 6 是用来从新激活〔reboot〕零碎,而 runlevel 1则是被用来让零碎进入管理工作能够进行的状态,这是预设的。假设没有-h也没有-r参数给shutdown。要想理解在停机〔halt〕或者从新开机〔reboot〕过程中做了哪些动作?你能够在这个文件/etc/inittab里看到这些runlevels相干的材料。</p>
<p data-tool=”mdnice编辑器” style=”font-size: 16px; padding-top: 8px; padding-bottom: 8px; margin: 0 0 20px; padding: 0; line-height: 1.8em; color: #3a3a3a;”>shutdown 参数阐明:</p>
<ul data-tool=”mdnice编辑器” style=”margin-top: 8px; margin-bottom: 8px; padding-left: 25px; color: black; list-style-type: disc;”>
<li><section style=”margin-top: 5px; margin-bottom: 5px; line-height: 26px; text-align: left; color: rgb(1,1,1); font-weight: 500;”><p style=”font-size: 16px; padding-top: 8px; padding-bottom: 8px; margin: 0 0 20px; padding: 0; line-height: 1.8em; color: #3a3a3a;”>[-t] 在扭转到其它runlevel之前,通知init多久当前关机。</p>
</section></li><li><section style=”margin-top: 5px; margin-bottom: 5px; line-height: 26px; text-align: left; color: rgb(1,1,1); font-weight: 500;”><p style=”font-size: 16px; padding-top: 8px; padding-bottom: 8px; margin: 0 0 20px; padding: 0; line-height: 1.8em; color: #3a3a3a;”>[-r] 重启计算器。</p>
</section></li><li><section style=”margin-top: 5px; margin-bottom: 5px; line-height: 26px; text-align: left; color: rgb(1,1,1); font-weight: 500;”><p style=”font-size: 16px; padding-top: 8px; padding-bottom: 8px; margin: 0 0 20px; padding: 0; line-height: 1.8em; color: #3a3a3a;”>[-k] 并不真正关机,只是送正告信号给每位登录者〔login〕。</p>
</section></li><li><section style=”margin-top: 5px; margin-bottom: 5px; line-height: 26px; text-align: left; color: rgb(1,1,1); font-weight: 500;”><p style=”font-size: 16px; padding-top: 8px; padding-bottom: 8px; margin: 0 0 20px; padding: 0; line-height: 1.8em; color: #3a3a3a;”>[-h] 关机后关闭电源〔halt〕。</p>
</section></li><li><section style=”margin-top: 5px; margin-bottom: 5px; line-height: 26px; text-align: left; color: rgb(1,1,1); font-weight: 500;”><p style=”font-size: 16px; padding-top: 8px; padding-bottom: 8px; margin: 0 0 20px; padding: 0; line-height: 1.8em; color: #3a3a3a;”>[-n] 不必init而是本人来关机。不激励应用这个选项,而且该选项所产生的结果往往不总是你所预期失去的。</p>
</section></li><li><section style=”margin-top: 5px; margin-bottom: 5px; line-height: 26px; text-align: left; color: rgb(1,1,1); font-weight: 500;”><p style=”font-size: 16px; padding-top: 8px; padding-bottom: 8px; margin: 0 0 20px; padding: 0; line-height: 1.8em; color: #3a3a3a;”>[-c] cancel current process勾销目前正在执行的关机程序。所以这个选项当然没有工夫参数,然而能够输</p>
</section></li><li><section style=”margin-top: 5px; margin-bottom: 5px; line-height: 26px; text-align: left; color: rgb(1,1,1); font-weight: 500;”><p style=”font-size: 16px; padding-top: 8px; padding-bottom: 8px; margin: 0 0 20px; padding: 0; line-height: 1.8em; color: #3a3a3a;”>一个用来解释的讯息,而这信息将会送到每位使用者。</p>
</section></li><li><section style=”margin-top: 5px; margin-bottom: 5px; line-height: 26px; text-align: left; color: rgb(1,1,1); font-weight: 500;”><p style=”font-size: 16px; padding-top: 8px; padding-bottom: 8px; margin: 0 0 20px; padding: 0; line-height: 1.8em; color: #3a3a3a;”>[-f] 在重启计算器〔reboot〕时疏忽fsck。</p>
</section></li><li><section style=”margin-top: 5px; margin-bottom: 5px; line-height: 26px; text-align: left; color: rgb(1,1,1); font-weight: 500;”><p style=”font-size: 16px; padding-top: 8px; padding-bottom: 8px; margin: 0 0 20px; padding: 0; line-height: 1.8em; color: #3a3a3a;”>[-F] 在重启计算器〔reboot〕时强制fsck。</p>
</section></li><li><section style=”margin-top: 5px; margin-bottom: 5px; line-height: 26px; text-align: left; color: rgb(1,1,1); font-weight: 500;”><p style=”font-size: 16px; padding-top: 8px; padding-bottom: 8px; margin: 0 0 20px; padding: 0; line-height: 1.8em; color: #3a3a3a;”>[-time] 设定关机〔shutdown〕前的工夫。</p>
</section></li></ul>
<p data-tool=”mdnice编辑器” style=”font-size: 16px; padding-top: 8px; padding-bottom: 8px; margin: 0 0 20px; padding: 0; line-height: 1.8em; color: #3a3a3a;”>2.halt 最简略的关机命令</p>
<p data-tool=”mdnice编辑器” style=”font-size: 16px; padding-top: 8px; padding-bottom: 8px; margin: 0 0 20px; padding: 0; line-height: 1.8em; color: #3a3a3a;”>用halt命令来关机时,理论调用的是shutdown -h。halt 执行时将杀死利用过程,执行sync零碎调用文件系统写操作实现后就会进行内核。
halt 参数阐明:</p>
<ul data-tool=”mdnice编辑器” style=”margin-top: 8px; margin-bottom: 8px; padding-left: 25px; color: black; list-style-type: disc;”>
<li><section style=”margin-top: 5px; margin-bottom: 5px; line-height: 26px; text-align: left; color: rgb(1,1,1); font-weight: 500;”>[-n] 避免sync零碎调用,它用在用fsck修补根分区之后,以阻止内核用老版本的超级块〔superblock〕笼罩修补过的超级块。</section></li><li><section style=”margin-top: 5px; margin-bottom: 5px; line-height: 26px; text-align: left; color: rgb(1,1,1); font-weight: 500;”>[-w] 并不是真正的重启或关机,只是写wtmp〔/var/log/wtmp〕纪录。</section></li><li><section style=”margin-top: 5px; margin-bottom: 5px; line-height: 26px; text-align: left; color: rgb(1,1,1); font-weight: 500;”>[-d] 不写wtmp纪录〔已蕴含在选项[-n]中〕。</section></li><li><section style=”margin-top: 5px; margin-bottom: 5px; line-height: 26px; text-align: left; color: rgb(1,1,1); font-weight: 500;”>[-f] 没有调用shutdown而强制关机或重启。</section></li><li><section style=”margin-top: 5px; margin-bottom: 5px; line-height: 26px; text-align: left; color: rgb(1,1,1); font-weight: 500;”>[-i] 关机〔或重启〕前关掉所有的网络接口。</section></li><li><section style=”margin-top: 5px; margin-bottom: 5px; line-height: 26px; text-align: left; color: rgb(1,1,1); font-weight: 500;”>[-p] 该选项为缺省选项。就是关机时调用poweroff。</section></li></ul>
<p data-tool=”mdnice编辑器” style=”font-size: 16px; padding-top: 8px; padding-bottom: 8px; margin: 0 0 20px; padding: 0; line-height: 1.8em; color: #3a3a3a;”>3.poweroff 罕用的关机命令</p>
<p data-tool=”mdnice编辑器” style=”font-size: 16px; padding-top: 8px; padding-bottom: 8px; margin: 0 0 20px; padding: 0; line-height: 1.8em; color: #3a3a3a;”>对于poweroff,网上说它是halt命令的链接,根本用法和 halt 差不多,这里就不多说了。</p>
<p data-tool=”mdnice编辑器” style=”font-size: 16px; padding-top: 8px; padding-bottom: 8px; margin: 0 0 20px; padding: 0; line-height: 1.8em; color: #3a3a3a;”>4.init</p>
<p data-tool=”mdnice编辑器” style=”font-size: 16px; padding-top: 8px; padding-bottom: 8px; margin: 0 0 20px; padding: 0; line-height: 1.8em; color: #3a3a3a;”>init是所有过程的先人,他是Linux零碎操作中不可短少的程序之一。它的过程号始终为1,所以发送TERM信号给init会终止所有的用户过程,守护过程等。shutdown 就是应用这种机制。init定义了8个运行级别(runlevel),init 0为关机,init 1为重启。</p>
<p data-tool=”mdnice编辑器” style=”font-size: 16px; padding-top: 8px; padding-bottom: 8px; margin: 0 0 20px; padding: 0; line-height: 1.8em; color: #3a3a3a;”>5.reboot 重启命令</p>
<p data-tool=”mdnice编辑器” style=”font-size: 16px; padding-top: 8px; padding-bottom: 8px; margin: 0 0 20px; padding: 0; line-height: 1.8em; color: #3a3a3a;”>reboot的工作过程差不多跟halt一样。不过它是引发主机重启,而halt是关机。它的参数与halt相差不多。
以上就是良许教程网为各位朋友分享的对于Linux零碎关机命令之间的区别和各自的用法。想要理解更多Linux相干常识记得关注公众号“良许Linux”,或扫描下方二维码进行关注,更多干货等着你!
<img src=”https://lxlinux.superbed.verylink.top/item/5fe1af843ffa7d37b353b15f.jpg” alt=”公众号” style=”margin: 0 auto; max-width: 100%; width: 100%; border-radius: 5px; display: block; margin-bottom: 15px; height: auto;”></p>
</section>
发表回复