理解 Linux 中的 shutdown、poweroff、halt 和 reboot 命令
shutdown poweroff halt reboot
![](/data/attachment/album/201706/05/095810ydt5h18yh8etzhkx.jpg)


在本篇中，我们会向你解释 `shutdown`、`poweroff`、`halt` 以及 `reboot` 命令。我们会解释清楚当你用那些可用的选项执行的时候它们实际做了什么。


如果你想深入 Linux 服务器管理，那么为了有效和可靠的服务器管理，这些[重要的 Linux 命令](https://www.tecmint.com/60-commands-of-linux-a-guide-from-newbies-to-system-administrator/)你需要完全理解。


通常上，当你想要关闭或者重启你的机器时，你会运行下面之一的命令：


### shutdown 命令


`shutdown` 会给系统计划一个时间关机。它可以被用于停止、关机、重启机器。


你可以指定一个时间字符串（通常是 `now` 或者用 `hh:mm` 指定小时/分钟）作为第一个参数。额外地，你也可以设置一个广播信息在系统关闭前发送给所有已登录的用户。


重要：如果使用了时间参数，系统关机前 5 分钟，会创建 `/run/nologin` 文件。以确保没有人可以再登录。


`shutdown` 命令示例：



```
# shutdown
# shutdown now
# shutdown 13:20  
# shutdown -p now  ### 关闭机器
# shutdown -H now  ### 停止机器      
# shutdown -r09:35 ### 在 09:35am 重启机器

```

要取消即将进行的关机，只要输入下面的命令：



```
# shutdown -c

```

### halt 命令


`halt` 通知硬件来停止所有的 CPU 功能，但是仍然保持通电。你可以用它使系统处于低层维护状态。


注意在有些情况会它会完全关闭系统。下面是 `halt` 命令示例：



```
# halt             ### 停止机器
# halt -p          ### 关闭机器
# halt --reboot    ### 重启机器

```

### poweroff 命令


`poweroff` 会发送一个 ACPI 信号来通知系统关机。


下面是 `poweroff` 命令示例：



```
# poweroff           ### 关闭机器
# poweroff --halt    ### 停止机器
# poweroff --reboot  ### 重启机器

```

### reboot 命令


`reboot` 通知系统重启。



```
# reboot           ### 重启机器
# reboot --halt    ### 停止机器
# reboot -p        ### 关闭机器

```

就是这样了！如先前提到的，理解这些命令能够有效并可靠地在多用户环境下管理 Linux 服务器。你有一些额外的想法么？在评论区留言与我们分享。




---


作者简介：


Aaron Kili是一名 Linux 和 F.O.S.S 的爱好者，未来的 Linux 系统管理员、网站开发人员，目前是 TecMint 的内容创作者，他喜欢用电脑工作，并乐于分享知识。




---


via: <https://www.tecmint.com/shutdown-poweroff-halt-and-reboot-commands-in-linux/>


作者：[Aaron Kili](https://www.tecmint.com/author/aaronkili/) 译者：[geekpi](https://github.com/geekpi) 校对：[jasminepeng](https://github.com/jasminepeng)


本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译，[Linux中国](https://linux.cn/) 荣誉推出


OK
In this article, we will explain to you the difference between **shutdown**, **poweroff**, **halt** and **reboot** Linux commands. We will make clear what they actually do when you execute them with available options.

If you are hoping to dive into Linux server administration, then these are [some of the important Linux commands](https://www.tecmint.com/60-commands-of-linux-a-guide-from-newbies-to-system-administrator/) you need to fully understand for effective and reliable server administration.

Normally, when you want to turn off or reboot your machine, you’ll run one of the commands below:

### Shutdown Command

**shutdown** schedules a time for the system to be powered down. It may be used to halt, power-off or reboot the machine.

You may specify a time string (which is usually “**now**” or “**hh:mm**” for hour/minutes) as the first argument. Additionally, you may set a wall message to be sent to all logged-in users before the system goes down.

**Important**: If the time argument is used, 5 minutes before the system goes down the **/run/nologin** file is created to ensure that further logins will not be allowed.

Examples of shutdown commands:

# shutdown # shutdown now # shutdown 13:20 # shutdown -p now #poweroff the machine # shutdown -H now #halt the machine # shutdown -r09:35 #reboot the machine at 09:35am

To cancel a pending shutdown, simply type the command below:

# shutdown -c

### Halt Command

**halt** instructs the hardware to stop all CPU functions, but leaves it powered on. You can use it to get the system to a state where you can perform low level maintenance.

Note that in some cases it completely shuts down the system. Below are examples of halt commands:

# halt #halt the machine # halt -p #poweroff the machine # halt --reboot #reboot the machine

### Power off Command

**poweroff** sends an ACPI signal which instructs the system to power down.

The following are examples of poweroff commands:

# poweroff #poweroff the machine # poweroff --halt #halt the machine # poweroff --reboot #reboot the machine

### Reboot Command

**reboot** instructs the system to restart.

# reboot #reboot the machine # reboot --halt #halt the machine # reboot -p #poweroff the machine

That’s all! As mentioned earlier on, understanding these commands will enable to effectively and reliably manage Linux server in a multi-user environment. Do you have any additional ideas? Share them with us via the comments section below.

Shouldn’t it be uppercase

Reply`-P`

for power-off?Some of y’all are imbecile, there is a reason for having all 3 commands as they are similar but not the same. For instance, the

shutdowncommand will also write a shutdown script. Perhaps, you just want to do low-level maintenance,haltwill be a suitable command to use as it will stop all running process and stop the CPU as well.You will probably remember

Replyhaltquicker than`Shutdown -H`

and as forreboot, self explanatory. Easier to remember as opposed to`shutdown -r.`

, etc.Can I configure the amount of time the system is powered off during a reboot command? (Using Centos 7)

ReplyI would like to shutdown and poweroff machine. I have seen things like “

/usr/sbin/shutdown -h +0 && /usr/sbin/poweroff” However, the poweroff command kills the machine prior to allowing programs to execute shutdown scripts.I do not wish to simply run poweroff, because it does not execute program shutdown scripts and simply halts all processes. Is there a way to get a graceful shutdown AND power down the machine?

Replyis halt work like suspend ? and how to recover yourself from halt ?

Replyinit 6 reboot

Replyinit 0 shutdown

@4pr0p02

Thanks for sharing this; useful as well.

ReplyWhat is `

Replyhalt` use scene? `shutdown` and `reboot` are enough.@wudanyang

True, but halt command exists so we have to mention it too. Thanks for writing back.

ReplyUseless

ReplyNot tell the difference but only list those commands’ parameters

@Mickechen

There is really no difference, we explained this in their descriptions and with the example commands(they all work nearly in the same way, they may be used to perform related functionalities using particular options.)

ReplySo, basically “shutdown” command is all you need, safely speaking. :) I mean it does everything from halt, reboot, shutdown etc. that too whenever I want it to.

Reply@Tanmaya

Yes, you can only use if for all the other operations. Meaning these commands are not so different.

Replypoweroff master race

Reply