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

# whereis.1

`whereis` — 定位程序

## 名称

`whereis`

## 概要

`whereis [-abmqsux] [-BMS dir ... -f] program ...`

## 描述

`whereis` 实用程序在标准的二进制文件、手册页和源代码目录中查找指定的程序，并打印出所找到的路径。提供的程序名首先会去除前导路径名部分、由 [gzip(1)](/man/man1/gzip.1.md)、compress(1) 或 bzip2(1) 添加的单个尾部扩展名，以及源代码控制系统添加的前导 `s.` 或尾部 `,v`。

默认搜索路径是由 [sysctl(8)](/man/man8/sysctl.8.md) 实用程序为 “user.cs\_path” 字符串返回的字符串，并附加 **/usr/libexec** 和当前用户的 `$PATH`。手册页默认沿 `$MANPATH` 搜索。程序源代码位于一组已知的标准位置列表中，包括 **/usr/src** 和 **/usr/ports** 的所有子目录。

可用选项如下：

**`-B`** 指定搜索二进制文件的目录。需要 `-f` 选项。

**`-M`** 指定搜索手册页的目录。需要 `-f` 选项。

**`-S`** 指定搜索程序源代码的目录。需要 `-f` 选项。

**`-a`** 报告所有匹配项，而非仅报告每种请求类型的第一项。

**`-b`** 搜索二进制文件。

**`-f`** 界定 `-B`、`-M` 或 `-S` 选项后的目录列表，并指示 `program` 列表的开始。

**`-m`** 搜索手册页。

**`-q`** （“quiet”）。抑制在正常输出行前面输出实用程序名。这在 shell 命令行的反引号替换中使用时很方便，参见 [实例](#实例)。

**`-s`** 搜索源代码目录。

**`-u`** 搜索“不寻常”条目。如果一个文件没有每种请求类型的至少一个条目，则称其为不寻常。仅打印不寻常条目的名称。

**`-x`** 搜索源代码目录时不使用“昂贵”的工具。通常，在搜索源代码目录列表的所有一级子目录均未成功后，`whereis` 会请求 [locate(1)](/man/man1/locate.1.md) 代为查找该条目。由于这可能需要更长时间，可以使用 `-x` 关闭。

## 实例

以下命令查找 **/usr/bin** 下所有没有文档的实用程序：

```sh
whereis -m -u /usr/bin/*
```

切换到 [ls(1)](/man/man1/ls.1.md) 的源代码目录：

```sh
cd `whereis -sq ls`
```

## 参见

[find(1)](/man/man1/find.1.md), [locate(1)](/man/man1/locate.1.md), [man(1)](/man/man1/man.1.md), [which(1)](/man/man1/which.1.md), [sysctl(8)](/man/man8/sysctl.8.md)

## 历史

`whereis` 实用程序出现于 3.0BSD。本版本重新实现了在 4.4BSD 中丢失的历史功能。

## 作者

`whereis` 命令的本实现由 Jörg Wunsch 编写。

## 缺陷

`whereis` 实用程序的本重新实现并非与历史版本逐 bug 兼容。但相信它与 FreeBSD 2.2 到 FreeBSD 4.5 中附带的版本兼容。

指定 `-a` 选项时，`whereis` 实用程序可能会报告一些无关的源代码条目。


---

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