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

# pwd.1

`pwd` — 返回工作目录名

## 名称

`pwd`

## 概要

`pwd [-L | -P]`

## 描述

`pwd` 实用程序将当前工作目录的绝对路径名写入标准输出。

某些 shell 可能提供与本实用程序相似或相同的内建 `pwd` 命令。请参阅 [builtin(1)](/man/man1/builtin.1.md) 手册页。

选项如下：

**`-L`** 显示逻辑当前工作目录。

**`-P`** 显示物理当前工作目录（解析所有符号链接）。

如果未指定选项，则假定使用 `-L` 选项。

## 环境变量

`pwd` 使用的环境变量：

**`PWD`** 逻辑当前工作目录。

## 退出状态

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

## 实例

显示当前工作目录并解析符号链接：

```sh
$ /bin/pwd
/usr/src/sys/kern
```

显示逻辑当前目录，然后使用 file(1) 检查 **`/sys`** 目录：

```sh
$ /bin/pwd -L
/sys/kern
$ file /sys
/sys: symbolic link to usr/src/sys
```

## 参见

[builtin(1)](/man/man1/builtin.1.md), cd(1), [csh(1)](https://github.com/FreeBSD-Ask/freebsd-man-sc/blob/main/man1/csh.1.md), [realpath(1)](/man/man1/realpath.1.md), [sh(1)](/man/man1/sh.1.md), getcwd(3)

## 标准

`pwd` 实用程序遵循 IEEE Std 1003.1-2001 ("POSIX.1") 标准。

## 历史

`pwd` 命令首次出现于 Version 5 AT\&T UNIX。

## 缺陷

在 [csh(1)](https://github.com/FreeBSD-Ask/freebsd-man-sc/blob/main/man1/csh.1.md) 中，`dirs` 命令总是更快，因为它内建于该 shell。然而，在当前目录或其包含目录在 shell 进入之后被移动的罕见情况下，它可能给出不同的答案。

除非 shell 导出了 `PWD` 环境变量，否则 `-L` 选项不起作用。


---

# 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/pwd.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.
