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

# gunzip.1

`gzip` — 使用 Lempel-Ziv 编码 (LZ77) 的压缩/解压缩工具

## 名称

`gzip`, `gunzip`, `zcat`

## 概要

`gzip [-cdfhkLlNnqrtVv] [-S suffix] file [file [...]]`

`gunzip [-cfhkLNqrtVv] [-S suffix] file [file [...]]`

`zcat [-fhV] file [file [...]]`

## 描述

`gzip` 程序使用 Lempel-Ziv 编码 (LZ77) 压缩和解压缩文件。如果未指定 `files`，`gzip` 将从标准输入压缩，或解压到标准输出。在压缩模式下，每个 `file` 将被替换为另一个文件，并尽可能添加由 `-S` `suffix` 选项设置的后缀。

在解压模式下，将检查每个 `file` 是否存在，同时也会检查添加后缀后的文件。每个 `file` 参数必须包含一个独立的完整归档；当指定了多个 `files` 时，每个文件将依次被解压。

对于 `gzcat`，结果数据会以 [cat(1)](/man/man1/cat.1.md) 的方式串接。

如果以 `gunzip` 调用，则启用 `-d` 选项。如果以 `zcat` 或 `gzcat` 调用，则同时启用 `-c` 和 `-d` 选项。

此版本的 `gzip` 还能够解压使用 compress(1)、bzip2(1)、`lzip`、zstd(1) 或 [xz(1)](/man/man1/xz.1.md) 压缩的文件。

## 选项

选项如下：

**`-1`**, `--fast`、**`-2`**, **`-3`**, **`-4`**, **`-5`**, **`-6`**, **`-7`**, **`-8`**、**`-9`**, `--best` 这些选项改变所使用的压缩级别，其中 `-1` 选项最快，压缩率较低；`-9` 选项最慢，压缩率最优。默认压缩级别为 6。

**`-c`**, `--stdout`, `--to-stdout` 该选项指定输出将发送到标准输出流，保持文件不变。

**`-d`**, `--decompress`, `--uncompress` 该选项选择解压而非压缩。

**`-f`**, `--force` 该选项开启强制模式。允许处理有多个链接的文件、指向常规文件的符号链接、覆盖已存在的文件、从终端读取或写入终端，当与 `-c` 选项组合使用时，允许未压缩的数据原样通过。

**`-h`**, `--help` 该选项打印用法摘要并退出。

**`-k`**, `--keep` 该选项防止 `gzip` 在（解）压缩后删除输入文件。

**`-L`**, `--license` 该选项打印 `gzip` 的许可证。

**`-l`**, `--list` 该选项显示有关文件的压缩和未压缩大小、压缩率、未压缩文件名的信息。配合 `-v` 选项时，还会显示压缩方法、CRC、文件中嵌入的日期和时间。

**`-N`**, `--name` 该选项使输入文件中存储的文件名用作输出文件名。

**`-n`**, `--no-name` 该选项阻止文件名和时间戳存储在输出文件中。

**`-q`**, `--quiet` 使用该选项时，不打印任何警告或错误。

**`-r`**, `--recursive` 该选项使用 fts(3) 库逐个处理目录树中的文件。

**`-S`** `suffix`, `--suffix` `suffix` 该选项将默认后缀从 .gz 改为 `suffix`。

**`-t`**, `--test` 该选项将测试压缩文件的完整性。

**`-V`**, `--version` 该选项打印 `gzip` 程序的版本。

**`-v`**, `--verbose` 该选项开启详细模式，打印每个文件压缩后的压缩率。

## 环境变量

如果设置了环境变量 `GZIP`，它将被解析为以空白分隔的选项列表，在命令行上的任何选项之前处理。命令行上的选项将覆盖 `GZIP` 中的任何内容。

## 退出状态

`gzip` 实用程序成功时退出值为 0，发生错误时为 1，发生警告时为 2。

## 信号

`gzip` 响应以下信号：

**`SIGINFO`** 向标准错误报告进度。

## 参见

bzip2(1), compress(1), [xz(1)](/man/man1/xz.1.md), zstd(1), fts(3), zlib(3)

## 历史

`gzip` 程序最初由 Jean-loup Gailly 编写，采用 GNU 公共许可证授权。Matthew R. Green 基于可自由再分发的 zlib 库，为 NetBSD 1.3 发行介质编写了一个简单的前端。它被增强为在 NetBSD 2.0 上与原始 GNU `gzip` 程序在功能上基本兼容。

此 `gzip` 实现基于 NetBSD `gzip` 版本 20181111 移植，首次出现于 FreeBSD 7.0。

## 作者

此 `gzip` 实现由 Matthew R. Green <mrg@eterna.com.au> 编写，解包支持由 Xin LI <delphij@FreeBSD.org> 编写。

## 缺陷

根据 RFC 1952，记录的文件大小存储在 32 位整数中，因此无法表示大于 4GB 的文件。此限制也适用于 `gzip` 实用程序的 `-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/gzip.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.
