> 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/man1/rmdir.1.md).

# rmdir.1

`rmdir` — 删除目录

## 名称

`rmdir`

## 概要

`rmdir [-pv] directory ...`

## 描述

`rmdir` 实用程序删除由每个 `directory` 参数指定的目录项，前提是该目录为空。

参数按给定顺序处理。为同时删除父目录及其子目录，必须先指定子目录，以便 `rmdir` 尝试删除父目录时父目录为空。

可用选项如下：

**`-p`** 每个 `directory` 参数被视为路径名，从最后一个组件开始，如果组件为空则删除所有组件。（完全无差别的递归删除参见 [rm(1)](/man/man1/rm.1.md)。）

**`-v`** 详细输出，列出每个被删除的目录。

## 退出状态

`rmdir` 实用程序以以下值之一退出：

**0** 每个 `directory` 引用的是一个空目录并成功删除。

**1** 尝试删除一个或多个目录时发生错误。

**2** 参数无效。

## 实例

删除目录 `foobar`（如果为空）：

```sh
$ rmdir foobar
```

删除直至 `cow`（含）的所有目录，在第一个非空目录（如果有）处停止：

```sh
$ rmdir -p cow/horse/monkey
```

## 参见

[rm(1)](/man/man1/rm.1.md), rmdir(2)

## 标准

`rmdir` 实用程序预期兼容 IEEE Std 1003.2 ("POSIX.2")。

`-v` 选项是对该规范的扩展。

## 历史

`rmdir` 命令出现于 Version 1 AT\&T UNIX。


---

# 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/man1/rmdir.1.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.
