> For the complete documentation index, see [llms.txt](https://book.bsdcn.org/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://book.bsdcn.org/man/man8/shutdown.8.md).

# poweroff.8

`shutdown`, `poweroff` — 在指定时间关闭系统

## 名称

`shutdown`, `poweroff`

## 概要

`shutdown [-] [-c | -f | -h | -p | -r | -k] [-o [-n]] [-q] time [warning-message ...]`

`poweroff`

## 描述

`shutdown` 工具为超级用户提供了一种自动化的关机程序，可以在系统关闭时妥善地通知用户，使系统管理员、黑客和高手免于忽略这些细节。要使用 `shutdown` 命令，用户必须拥有 root 权限或是 operator 组的成员。

可用选项如下：

**`-c`** 系统在指定的时间进行电源循环（先断电再通电）。如果硬件不支持电源循环，系统将重启。目前，只有带有由 [ipmi(4)](https://github.com/FreeBSD-Ask/freebsd-man-sc/blob/main/man4/ipmi.4.md) 驱动支持的 BMC 且实现了此功能的系统才支持此标志。系统关机的持续时间取决于实现此功能的设备。

**`-f`** `shutdown` 命令忽略 **/var/run/noshutdown** 文件的存在。

**`-h`** 系统在指定的 `time` 停机。

**`-p`** 系统在指定的 `time` 停机并关闭电源（需要硬件支持，否则系统仅停机）。

**`-r`** 系统在指定的 `time` 重启。

**`-k`** 踢出所有人。`-k` 选项实际上不会停机系统，而是使系统保持多用户状态，但禁用登录（对除超级用户以外的所有人）。

**`-o`** 如果指定了 `-c`、`-h`、`-p` 或 `-r` 选项之一，`shutdown` 将执行 [fasthalt(8)](broken://pages/GDgVpsSustcOkyaoCGkN) 或 [fastboot(8)](broken://pages/xdOVqOGJl9epzxSLomtZ)，而不是向 [init(8)](/man/man8/init.8.md) 发送信号。

**`-n`** 如果指定了 `-o` 选项，通过向 [fasthalt(8)](broken://pages/GDgVpsSustcOkyaoCGkN) 或 [fastboot(8)](broken://pages/xdOVqOGJl9epzxSLomtZ) 传递 `-n` 来阻止文件系统缓存被刷新。此选项可能不应使用。

**`-q`** 静默关机。抑制向所有已登录用户发送的关于系统关机的警告消息。在抑制警告时提供 `warning-message` 是一个错误。

**`time`** `Time` 是 `shutdown` 关闭系统的时间，可以是不区分大小写的单词 `now`（表示立即关机），也可以是以下两种格式之一的未来时间：`+number` 或绝对时间规范。第一种形式在 `number` 个时间单位（默认为分钟）后关闭系统，第二种在指定的绝对时间关闭系统。

绝对时间可以用以下格式之一指定，未指定的部分默认为当前日期：

* `hhmm` 小时和分钟。
* `DDhhmm` 日、小时和分钟。
* `MMDDhhmm` 月、日、小时和分钟。
* `YYMMDDhhmm` 年（本世纪内）、月、日、小时和分钟。

年份 `YY` 相对于当前世纪解释，对稍过去的值有一年的容差（以适应年份交界时的输入）。`+number` 可以通过附加相应的后缀来指定以分钟以外的单位表示："**`s`**"、"**`sec`**"、"**`secs`**"、"**`m`**"、"**`min`**"、"**`mins`**"、"**`h`**"、"**`hour`**"、"**`hours`**"。单位后缀不区分大小写。如果指定了绝对时间但未指定日期，且该时间今天已经过去，`shutdown` 将假定指的是明天的同一时间。（如果指定了完整的日期且已经过去，`shutdown` 将打印错误并退出，不关闭系统。）

**`warning-message`** 任何其他参数构成警告消息，将广播给当前登录系统的用户。

**`-`** 如果提供 ‘`-`’ 作为选项，则从标准输入读取警告消息。

随着末日的临近，警告消息会以越来越频繁的间隔（从关机前十小时开始）显示在所有已登录用户的终端上。在关机前五分钟，或者如果关机时间不到五分钟则立即，通过创建 **/var/run/nologin** 并将警告消息复制到其中来禁用登录。如果用户尝试登录时此文件存在，[login(1)](/man/man1/login.1.md) 会打印其内容并退出。该文件在 `shutdown` 退出前被删除。

在关机时，系统日志中会写入一条消息，包含关机时间、发起关机的人员和原因。然后向 [init(8)](/man/man8/init.8.md) 发送相应的信号，分别停机、重启或将系统降至单用户状态（取决于上述选项）。关机时间和警告消息会放置在 **/var/run/nologin** 中，用于告知用户系统何时恢复以及为何关机（或其他信息）。

可以通过终止 `shutdown` 进程来取消计划中的关机（`SIGTERM` 即可）。`shutdown` 创建的 **/var/run/nologin** 文件将被自动删除。

如果 **/var/run/noshutdown** 文件存在，`shutdown` 退出且不对系统执行任何操作。

不带选项运行时，`shutdown` 工具将在指定的 `time` 将系统置于单用户模式。

调用 "`poweroff`" 等效于运行：

```sh
shutdown -p now
```

## 文件

**/var/run/nologin** 告知 [login(1)](/man/man1/login.1.md) 不要让任何人登录。

**/var/run/noshutdown** 阻止 `shutdown` 在系统上发起操作。可使用 `-f` 选项覆盖。

## 实例

在 30 分钟后重启系统，并向所有当前登录用户的终端显示警告消息：

```sh
# shutdown -r +30 "System will reboot"
```

在 23:30 停机系统（使用任一格式）：

```sh
# shutdown -h 2330
```

```sh
# shutdown -h 23:30
```

在 6 月 15 日 10:00 关闭系统电源：

```sh
# shutdown -p 06151000
```

## 兼容性

为了向后兼容，任何绝对时间格式中的小时和分钟可以用冒号（"**:**"）分隔。例如，`hh:mm` 被接受为等效于 `hhmm`。

## 参见

[kill(1)](/man/man1/kill.1.md), [login(1)](/man/man1/login.1.md), [wall(1)](https://github.com/FreeBSD-Ask/freebsd-man-sc/blob/main/man1/wall.1.md), nologin(5), [halt(8)](broken://pages/gQRQWMx2sWVI2IOPK0Lm), [init(8)](/man/man8/init.8.md), [reboot(8)](/man/man8/reboot.8.md)

## 历史

`shutdown` 命令最初由 Ian Johnstone 为 UNSW 修改的 AT\&T UNIX 第 6 版编写。它经过修改后被纳入 4.1BSD。


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://book.bsdcn.org/man/man8/shutdown.8.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
