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

# mkdir.1

`mkdir` — 创建目录

## 名称

`mkdir`

## 概要

`mkdir [-pv] [-m mode] directory_name ...`

## 描述

`mkdir` 实用程序按指定顺序以操作数指定的名称创建目录，使用模式 “`rwxrwxrwx`”（0777）并根据当前 umask(2) 修改。

选项如下：

**`-m`** `mode` 将最终创建的目录的文件权限位设置为指定模式。`mode` 参数可为 [chmod(1)](/man/man1/chmod.1.md) 命令中指定的任何格式。如果指定了符号模式，操作字符 `+` 和 `-` 相对于初始模式 “`a=rwx`” 解释。

**`-p`** 按需创建中间目录。如果未指定此选项，每个操作数的完整路径前缀必须已存在。另一方面，指定此选项时，如果作为操作数给出的目录已存在，不会报告错误。中间目录以权限位 “`rwxrwxrwx`”（0777）创建，并根据当前 umask 修改，加上所有者的写和搜索权限。

**`-v`** 创建目录时显示详细信息，列出所创建的目录。

用户必须对父目录具有写权限。

## 退出状态

`mkdir` 实用程序成功时退出值为 0，发生错误时大于 0。

## 实例

创建名为 `foobar` 的目录：

```sh
$ mkdir foobar
```

创建名为 `foobar` 的目录并将其文件模式设置为 700：

```sh
$ mkdir -m 700 foobar
```

创建名为 `cow/horse/monkey` 的目录，按需创建任何不存在的中间目录：

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

## 兼容性

`-v` 选项是非标准的，不建议在脚本中使用。

## 参见

[rmdir(1)](/man/man1/rmdir.1.md)

## 标准

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

## 历史

`mkdir` 命令出现于 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/mkdir.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.
