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

# head.1

`head` — 显示文件的开头若干行

## 名称

`head`

## 概要

`head [-qv] [-n count | -c bytes] [file]`

## 描述

该过滤器显示每个指定文件的前 `count` 行或 `bytes` 字节，如果未指定文件则显示标准输入的内容。如果省略 `count`，默认为 10。

选项如下：

**`-c`** `bytes`, `--bytes`=`bytes` 打印每个指定文件的 `bytes` 字节。

**`-n`** `count`, `--lines`=`count` 打印每个指定文件的 `count` 行。`count` 和 `bytes` 均可使用 expand\_number(3) 所支持的大小后缀来指定。

**`-q`**, `--quiet`, `--silent` 当检查多个文件时，禁止打印文件头。

**`-v`**, `--verbose` 在每个文件前添加文件头。

如果指定了多个文件，或使用了 `-v` 选项，每个文件前都会有一个由字符串 “==> XXX <==” 组成的文件头，其中 “XXX” 是文件名。`-q` 选项在所有情况下都禁止打印文件头。

## 退出状态

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

## 实例

显示文件 `foo` 的前 500 行：

```sh
$ head -n 500 foo
```

`head` 可以与 [tail(1)](https://github.com/FreeBSD-Ask/freebsd-man-sc/blob/main/man1/tail.1.md) 配合使用，例如只显示文件 `foo` 的第 500 行：

```sh
$ head -n 500 foo | tail -n 1
```

## 参见

[tail(1)](https://github.com/FreeBSD-Ask/freebsd-man-sc/blob/main/man1/tail.1.md), expand\_number(3)

## 历史

`head` 命令首次出现于 PWB 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/head.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.
