gzip 中文man页面

系统
Gzip 采用Lempel-Ziv 编码算法(LZ77)压缩给定文件的大小。在可能的情况下, 每个文件被具有扩展名 .gz, 的文件所替换, 同时保留原属主状态,存取和修改时间 (在VMS系统下缺省扩展名为 -gz 在MSDOS、OS/2 FAT, Windows NT FAT 和Atari系统下,缺省扩展名为 z ) 如果未指定文件名,或者指定了一个名为"-"的文件名,则从标准输入读取数据,压缩的结果输出到标准输出。 Gzip 只尝试压缩常规文件,特别地,它将忽略符号连接。

命令名

gzip, gunzip, zcat - 压缩或展开文件 

总揽

gzip [ -acdfhlLnNrtvV19 ] [-S 后缀] [ 文件名 ... ]
gunzip [ -acfhlLnNrtvV ] [-S 后缀] [ 文件名 ... ]
zcat [ -fhLV ] [ 文件名 ...

描述

Gzip 采用Lempel-Ziv 编码算法(LZ77)压缩给定文件的大小。在可能的情况下, 每个文件被具有扩展名 .gz, 的文件所替换, 同时保留原属主状态,存取和修改时间 (在VMS系统下缺省扩展名为 -gz 在MSDOS、OS/2 FAT, Windows NT FAT 和Atari系统下,缺省扩展名为 z ) 如果未指定文件名,或者指定了一个名为"-"的文件名,则从标准输入读取数据,压缩的结果输出到标准输出。 Gzip 只尝试压缩常规文件,特别地,它将忽略符号连接。

如果压缩后的文件名对于所在的文件系统来说太长,
gzip 会将其截断。 Gzip 只尝试截断文件名中大于3个字符的段(每个段由点分隔)。如果文件名只由较小的段组成,最长的段将被截断。例如,如果文件名的长度限制是14个字符,文件gzip.msdos.exe 将被压缩为gzi.msd.exe.gz。在没有文件名长度限制的系统中,文件名将不会被截断。
缺省情况下,
gzip 将原始文件名和时间信息保存在压缩后的文件中。当采用 -N 选项解压缩文件时,这些信息将被利用。在经过文件传输后文件名被截断及时间信息未被保留的情况下,这些信息将将用于恢复文件名及时间信息。
gzip -d 或者 gunzip 以及 zcat. 可以将压缩后的文件恢复到原始的形式。如果保留在压缩文件中的原始文件名不适合于当前的文件系统,将根据原文件名新建一个合法的文件名。
gunzip
将命令行中以.gz, -gz, .z, -z, _z 或 .Z结尾并具有正确标志头的文件解压缩,并以去掉扩展名的解压缩文件替换原文件。 gunzip 也能识别扩展名为 .tgz.taz 的文件,并将其分别当作 .tar.gz.tar.Z 的缩写。在压缩时,如果采用 .tar 扩展名则需要对文件名进行截断处理时, gzip 将采用 .tgz 作为扩展名。
gunzip
目前能够解压由 gzip, zip, compress, compress -H 以及 pack 产生的文件。对输入格式的检测是自动的。当采用前两种格式时, gunzip 检查一个32位的CRC校验码。对于 pack, gunzip 则检查压缩前的数据长度。标准的 compress 格式的设计无法实现一致性检查。但有时 gunzip 仍然能检测到坏的.Z文件。如果你在解压一个.Z文件时出现错误,不要简单地因为标准的 uncompress 没有报错就认定.Z文件是正确的。这通常意味着标准的 uncompress 没有检查它的输入数据,而盲目地产生了错误的输出。SCO的compress -H格式(lzh压缩方法)不包含CRC校验码,但也允许一些一致性检查。
zip 生成的文件, 如果其内容只有一个文件并且是以'deflation'方式压缩的,则可由gzip解压。这一特性只是为了方便将tar.zip 格式的文件转换为tar.gz格式而加入的。要解压含有多个文件的zip文件,请用 unzip.
zcat
的功能与 gunzip -c. 相同。 (在一些系统中, zcat 可能被安装成 gzcat 以保留 compress 与zcat的原有连接。) zcat 将命令行中列出的文件或由标准输入输入的数据解压,解压后的数据写到标准输出。 zcat 解压具有正确标志头的文件,而不管其是否带有 .gz 后缀。
Gzip
采用 zip 和 PKZIP 中所采用的Lempel-Ziv算法。得到的压缩比依赖于输入数据的大小以及公用子串的分布。例如源程序和英文文档能够压缩60-70%。压缩比通常比LZW( compress 采用的算法)、Huffman编码( pack 所采用的算法)、以及自适应Huffman编码( RI compact ) 等方法要好得多。
即使压缩后的文件略大于原文件,压缩也照样进行。最坏的情况下,多出的数据包括
gzip文件头中的若干个字节,加上每块32K的5个字节,或者,对于大文件来说0.015% 的放大率。注意实际占用的硬盘块数目几乎从不增加。 gzip 在压缩和解压缩时保留原文件的属主和时间信息。

选项

-a --ascii
Ascii文本模式:按本地习惯转换行结束符。该选项仅在一些非Unix 系统上有效。对于MSDOS,在压缩时CR LF(译注:即回车和换行符)被转换为LF,在解压时LF被转换为CR LF。
-c --stdout --to-stdout
将结果写到标准输出;原文件保持不变。如果有多个输入文件,输出将由一系列独立的压缩文件组成。如果想得到较好的压缩率,在压缩前应将多个文件连在一起。
-d --decompress --uncompress
解压缩。
-f --force
强制压缩和解压缩,即使指定文件具有多重连接,或相应文件已经存在,或压缩数据来自或写往一个终端。如果输入数据是 gzip 无法识别的格式,同时在命令行中也给出了--stdout选项,gzip将把输入数据拷贝至标准输出而不做任何改动,就象cat所做的一样。如果未给出 -f 选项,并且未在后台运行, gzip 会提示用户以确认是否覆盖一个已存在的文件。
-h --help
显示帮助信息然后退出。
-l --list
列出每个压缩文件的如下项目:


    compressed size:  压缩文件的长度
    uncompressed size:  压缩前文件的长度
    ratio: 压缩率(如果未知则为0.0%)
    uncompressed_name: 压缩前的文件名

对于非gzip格式的文件,压缩前文件长度显示为-1,例如由compress压缩的.Z文件。可用下列命令得到这种文件压缩前的长度:


    zcat file.Z | wc -c

如果同时指定了--verbose选项,下列项目也被列出:


    method: 压缩方式
    crc: 未压缩数据的32位CRC校验码
    date & time: 压缩前文件的时间信息

目前支持的压缩方式有deflate、compress、lzh(SCO下的compress -H)以及pack等方式。对于非gzip格式的文件,crc校验码显示为ffffffff。

若指定了--name选项,如果有的话,压缩前文件名,日期以及时间是保存在压缩文件中的内容。

若指定了--verbose选项,还将列出所有文件的长度总和,除非某些文件的长度未知。若指定--quiet选项,将不显示标题和合计两行内容。

-L --license
显示 gzip 的许可证信息然后退出。
-n --no-name
在压缩时,缺省不保留原始文件名和时间信息。(如果必须对文件名作截断处理,则原始文件名总是被保存。) 在解压缩时,即使有也不恢复原始文件名(仅将压缩文件名中的 gzip 后缀去掉)和时间信息(拷贝压缩文件中相应信息)。该选项是压缩时的缺省选项。
-N --name
在压缩时总是保存原始文件名和时间信息;该选项为缺省选项。在解压缩时,如果存在原始文件名和时间信息则恢复之。该选项可用于对文件名长度有限制的系统,以及经过文件传输后丢失时间信息的情况。
-q --quiet
压制所有警告信息。
-r --recursive
递归地访问目录结构。如果命令行中有目录名, gzip 将进入目录并压缩所有找到的文件(如果执行的命令是 gunzip 则对其解压缩)。
-S .suf --suffix .suf
采用.suf后缀取代.gz后缀。可以指定任何后缀,但应避免使用除了.z和.gz以外的其它后缀,以免文件传输到其它系统时发生混淆。一个空后缀将迫使gunzip 解压缩所有文件而不管它具有什么样的后缀,例如:


    gunzip -S "" *       (在MSDOS下用*.*替换*)

以前版本的gzip采用.z后缀。为了避免与 pack(1). 冲突,后来作了改动。

-t --test
测试。检查压缩文件的完整性。
-v --verbose
详尽模式。显示每个压缩或解压缩文件的名字和压缩率。
-V --version
版本。显示版本号和编译选项后退出。 Version. Display the version number and compilation options then quit.
-# --fast --best
用指定的数字 # 调整压缩速度,其中 -1--fast 对应最快压缩方式(压缩率较低), -9--best 对应最慢压缩方式(压缩率***)。缺省的压缩级别为
- (也就是说,以速度为代价偏向于高压缩率)。

高级用法

多个被压缩的文件可以连在一起。在这种情况下, gunzip 能一次解压所有文件。例如:


      gzip -c file1  > foo.gz
      gzip -c file2 >> foo.gz

然后
      gunzip -c foo

上面的命令等价于


      cat file1 file2

如果.gz文件中的某一个文件损坏,其他文件仍可以恢复(如果损坏的文件被删除的话)。而且一次压缩所有文件能得到较好的压缩率:


      cat file1 file2 | gzip > foo.gz

上面用法的压缩率比下面用法的高:


      gzip -c file1 file2 > foo.gz

如果想重新压缩连接起来的文件以得到较高的压缩率,可以用下面的命令:


      gzip -cd old.gz | gzip > new.gz

如果一个压缩文件由多个文件组成,--list选项只能列出***一个成员的解压后文件长度和CRC校验码。如果需要所有成员的解压后文件长度,可用如下命令:


      gzip -cd file.gz | wc -c

如果想要产生一个具有多个成员的存档文件,以便将来能够独立地取出其中的成员,可以用tar或zip这样的归档软件。GNU tar支持-z选项,可直接调用gzip。gzip设计为 tar的补充,而非它的取代物。  

环境变量

环境变量 GZIP 能够控制一系列 gzip 的缺省选项。这些选项被首先解释,并且能被命令行参数中的直接定义覆盖。例如:
      在sh下:    GZIP="-8v --name"; export GZIP
      在csh下:   setenv GZIP "-8v --name"
      在MSDOS下: set GZIP=-8v --name

在Vax/VMS系统中,为了避免与调用该程序的符号设置冲突,该环境变量名为GZIP_OPT。  

另见

znew(1), zcmp(1), zmore(1), zforce(1), gzexe(1), zip(1), unzip(1), compress(1), pack(1), compact(1)  

#p#

NAME

gzip, gunzip, zcat - compress or expand files  

SYNOPSIS

gzip [ -acdfhlLnNrtvV19 ] [-S suffix] [ name ... ]
gunzip [ -acfhlLnNrtvV ] [-S suffix] [ name ... ]
zcat [ -fhLV ] [ name ... ]  

DESCRIPTION

Gzip reduces the size of the named files using Lempel-Ziv coding (LZ77). Whenever possible, each file is replaced by one with the extension .gz, while keeping the same ownership modes, access and modification times. (The default extension is -gz for VMS, z for MSDOS, OS/2 FAT, Windows NT FAT and Atari.) If no files are specified, or if a file name is "-", the standard input is compressed to the standard output. Gzip will only attempt to compress regular files. In particular, it will ignore symbolic links.

If the compressed file name is too long for its file system, gzip truncates it. Gzip attempts to truncate only the parts of the file name longer than 3 characters. (A part is delimited by dots.) If the name consists of small parts only, the longest parts are truncated. For example, if file names are limited to 14 characters, gzip.msdos.exe is compressed to gzi.msd.exe.gz. Names are not truncated on systems which do not have a limit on file name length.

By default, gzip keeps the original file name and timestamp in the compressed file. These are used when decompressing the file with the -N option. This is useful when the compressed file name was truncated or when the time stamp was not preserved after a file transfer.

Compressed files can be restored to their original form using gzip -d or gunzip or zcat. If the original name saved in the compressed file is not suitable for its file system, a new name is constructed from the original one to make it legal.

gunzip takes a list of files on its command line and replaces each file whose name ends with .gz, -gz, .z, -z, _z or .Z and which begins with the correct magic number with an uncompressed file without the original extension. gunzip also recognizes the special extensions .tgz and .taz as shorthands for .tar.gz and .tar.Z respectively. When compressing, gzip uses the .tgz extension if necessary instead of truncating a file with a .tar extension.

gunzip can currently decompress files created by gzip, zip, compress, compress -H or pack. The detection of the input format is automatic. When using the first two formats, gunzip checks a 32 bit CRC. For pack, gunzip checks the uncompressed length. The standard compress format was not designed to allow consistency checks. However gunzip is sometimes able to detect a bad .Z file. If you get an error when uncompressing a .Z file, do not assume that the .Z file is correct simply because the standard uncompress does not complain. This generally means that the standard uncompress does not check its input, and happily generates garbage output. The SCO compress -H format (lzh compression method) does not include a CRC but also allows some consistency checks.

Files created by zip can be uncompressed by gzip only if they have a single member compressed with the 'deflation' method. This feature is only intended to help conversion of tar.zip files to the tar.gz format. To extract zip files with several members, use unzip instead of gunzip.

zcat is identical to gunzip -c. (On some systems, zcat may be installed as gzcat to preserve the original link to compress.) zcat uncompresses either a list of files on the command line or its standard input and writes the uncompressed data on standard output. zcat will uncompress files that have the correct magic number whether they have a .gz suffix or not.

Gzip uses the Lempel-Ziv algorithm used in zip and PKZIP. The amount of compression obtained depends on the size of the input and the distribution of common substrings. Typically, text such as source code or English is reduced by 60-70%. Compression is generally much better than that achieved by LZW (as used in compress), Huffman coding (as used in pack), or adaptive Huffman coding (compact).

Compression is always performed, even if the compressed file is slightly larger than the original. The worst case expansion is a few bytes for the gzip file header, plus 5 bytes every 32K block, or an expansion ratio of 0.015% for large files. Note that the actual number of used disk blocks almost never increases. gzip preserves the mode, ownership and timestamps of files when compressing or decompressing. 

OPTIONS

-a --ascii
Ascii text mode: convert end-of-lines using local conventions. This option is supported only on some non-Unix systems. For MSDOS, CR LF is converted to LF when compressing, and LF is converted to CR LF when decompressing.
-c --stdout --to-stdout
Write output on standard output; keep original files unchanged. If there are several input files, the output consists of a sequence of independently compressed members. To obtain better compression, concatenate all input files before compressing them.
-d --decompress --uncompress
Decompress.
-f --force
Force compression or decompression even if the file has multiple links or the corresponding file already exists, or if the compressed data is read from or written to a terminal. If the input data is not in a format recognized by gzip, and if the option --stdout is also given, copy the input data without change to the standard ouput: let zcat behave as cat. If -f is not given, and when not running in the background, gzip prompts to verify whether an existing file should be overwritten.
-h --help
Display a help screen and quit.
-l --list
For each compressed file, list the following fields:


    compressed size: size of the compressed file
    uncompressed size: size of the uncompressed file
    ratio: compression ratio (0.0% if unknown)
    uncompressed_name: name of the uncompressed file

The uncompressed size is given as -1 for files not in gzip format, such as compressed .Z files. To get the uncompressed size for such a file, you can use:


    zcat file.Z | wc -c

In combination with the --verbose option, the following fields are also displayed:


    method: compression method
    crc: the 32-bit CRC of the uncompressed data
    date & time: time stamp for the uncompressed file

The compression methods currently supported are deflate, compress, lzh (SCO compress -H) and pack. The crc is given as ffffffff for a file not in gzip format.

With --name, the uncompressed name, date and time are those stored within the compress file if present.

With --verbose, the size totals and compression ratio for all files is also displayed, unless some sizes are unknown. With --quiet, the title and totals lines are not displayed.

-L --license
Display the gzip license and quit.
-n --no-name
When compressing, do not save the original file name and time stamp by default. (The original name is always saved if the name had to be truncated.) When decompressing, do not restore the original file name if present (remove only the gzip suffix from the compressed file name) and do not restore the original time stamp if present (copy it from the compressed file). This option is the default when decompressing.
-N --name
When compressing, always save the original file name and time stamp; this is the default. When decompressing, restore the original file name and time stamp if present. This option is useful on systems which have a limit on file name length or when the time stamp has been lost after a file transfer.
-q --quiet
Suppress all warnings.
-r --recursive
Travel the directory structure recursively. If any of the file names specified on the command line are directories, gzip will descend into the directory and compress all the files it finds there (or decompress them in the case of gunzip ).
-S .suf --suffix .suf
Use suffix .suf instead of .gz. Any suffix can be given, but suffixes other than .z and .gz should be avoided to avoid confusion when files are transferred to other systems. A null suffix forces gunzip to try decompression on all given files regardless of suffix, as in:


    gunzip -S "" *       (*.* for MSDOS)

Previous versions of gzip used the .z suffix. This was changed to avoid a conflict with pack(1).

-t --test
Test. Check the compressed file integrity.
-v --verbose
Verbose. Display the name and percentage reduction for each file compressed or decompressed.
-V --version
Version. Display the version number and compilation options then quit.
-# --fast --best
Regulate the speed of compression using the specified digit #, where -1 or --fast indicates the fastest compression method (less compression) and -9 or --best indicates the slowest compression method (best compression). The default compression level is -6 (that is, biased towards high compression at expense of speed).

ADVANCED USAGE

Multiple compressed files can be concatenated. In this case, gunzip will extract all members at once. For example:


      gzip -c file1  > foo.gz
      gzip -c file2 >> foo.gz

Then


      gunzip -c foo

is equivalent to


      cat file1 file2

In case of damage to one member of a .gz file, other members can still be recovered (if the damaged member is removed). However, you can get better compression by compressing all members at once:


      cat file1 file2 | gzip > foo.gz

compresses better than


      gzip -c file1 file2 > foo.gz

If you want to recompress concatenated files to get better compression, do:


      gzip -cd old.gz | gzip > new.gz

If a compressed file consists of several members, the uncompressed size and CRC reported by the --list option applies to the last member only. If you need the uncompressed size for all members, you can use:


      gzip -cd file.gz | wc -c

If you wish to create a single archive file with multiple members so that members can later be extracted independently, use an archiver such as tar or zip. GNU tar supports the -z option to invoke gzip transparently. gzip is designed as a complement to tar, not as a replacement.  

ENVIRONMENT

The environment variable GZIP can hold a set of default options for gzip. These options are interpreted first and can be overwritten by explicit command line parameters. For example:
      for sh:    GZIP="-8v --name"; export GZIP
      for csh:   setenv GZIP "-8v --name"
      for MSDOS: set GZIP=-8v --name

On Vax/VMS, the name of the environment variable is GZIP_OPT, to avoid a conflict with the symbol set for invocation of the program.  

SEE ALSO

znew(1), zcmp(1), zmore(1), zforce(1), gzexe(1), zip(1), unzip(1), compress(1), pack(1), compact(1)

责任编辑:韩亚珊 来源: CMPP.net
相关推荐

2011-08-24 16:48:36

man中文man

2011-08-15 10:21:09

man中文man

2011-08-11 16:11:49

at中文man

2011-08-25 10:21:56

man.conf中文man

2011-08-25 15:39:42

fcloseall中文man

2011-08-25 15:00:15

cfgetispeed中文man

2011-08-19 18:35:50

issue中文man

2011-08-25 17:03:51

pclose中文man

2011-08-25 17:40:25

setvbuf中文man

2011-08-23 14:21:16

poweroff中文man

2011-08-24 15:52:59

intro中文man

2011-08-23 13:40:31

2011-08-25 15:54:08

ferror中文man

2011-08-25 17:24:54

puts中文man

2011-08-25 18:34:55

ungetc中文man

2011-08-23 10:03:40

useradd中文man

2011-08-23 10:29:02

chpasswd中文man

2011-08-23 10:34:22

convertquot中文man

2011-08-23 15:39:34

rpmbuild中文man

2011-08-24 15:48:38

INSERT中文man
点赞
收藏

51CTO技术栈公众号