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

# seq.1

`seq` — 打印数字序列

## 名称

`seq`

## 概要

`seq [-w] [-f format] [-s string] [-t string] [first [incr]] last`

## 描述

`seq` 实用程序打印一个数字序列，每行一个（默认），从 `first`（默认 1）开始，尽可能接近 `last`，增量为 `incr`（默认 1）。当 `first` 大于 `last` 时，默认 `incr` 为 -1。

所有数字均按浮点数解释。

通常整数值以十进制整数形式打印。

`seq` 实用程序接受以下选项：

**`-f`** `format`, **`--format`** `format` 使用 printf(3) 风格的 `format` 打印每个数字。仅 `A`、`a`、`E`、`e`、`F`、`f`、`G`、`g` 和 `%` 转换字符有效，还可附带可选的标志和可选的数值最小字段宽度或精度。`format` 可以包含 ANSI X3.159-1989（"ANSI C89"）中定义的反斜杠表示法的字符转义序列。默认值为 `%g`。

**`-s`** `string`, **`--separator`** `string` 使用 `string` 分隔数字。`string` 可以包含 ANSI X3.159-1989（"ANSI C89"）中定义的反斜杠表示法的字符转义序列。默认值为 **`\n`**。

**`-t`** `string`, **`--terminator`** `string` 使用 `string` 终止数字序列。`string` 可以包含 ANSI X3.159-1989（"ANSI C89"）中定义的反斜杠表示法的字符转义序列。当默认分隔符不包含 **`\n`** 时，此选项很有用。

**`-w`**, **`--fixed-width`** 通过必要时补零来使所有数字的宽度相等。此选项与 `-f` 选项一起使用时无效。如果有任何序列数字将以指数表示法打印，则默认转换更改为 `%e`。

## 退出状态

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

## 实例

生成从 1 到 3（含）的序列，默认增量为 1：

```sh
# seq 1 3
1
2
3
```

生成从 3 到 1（含）的序列，默认增量为 -1：

```sh
# seq 3 1
3
2
1
```

生成从 0 到 0.1（含）的序列，增量为 0.05，并用前导零填充：

```sh
# seq -w 0 .05 .1
0.00
0.05
0.10
```

生成从 1 到 3（含）的序列，默认增量为 1，使用自定义分隔符字符串和自定义终止符：

```sh
# seq -s "-->" -t "[end of list]\n" 1 3
1-->2-->3-->[end of list]
```

生成从 1 到 2（含）的序列，增量为 0.2，并使用 printf(3) 风格格式打印结果，小数点后保留两位：

```sh
# seq -f %.2f 1 0.2 2
1.00
1.20
1.40
1.60
1.80
2.00
```

## 参见

jot(1), printf(1), printf(3)

## 历史

`seq` 命令首次出现在 Version 8 AT\&T UNIX 中。`seq` 命令出现在 NetBSD 3.0 中，并移植到 FreeBSD 9.0。此命令基于 Bell Labs 的 Plan 9 中同名命令和 GNU core utilities。GNU `seq` 命令首次出现在 1.13 shell utilities 发行版中。

## 缺陷

`-w` 选项在处理从纯浮点表示到指数表示的转换时不太理想。`seq` 命令与其他实现并非逐 bug 兼容。


---

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