[Previous] [Contents] [Next]


Compress or expand files (GNU)


Compress/uncompress files:

    gzip [-cdfhLrtvV19] [name...]

Uncompress only:

    gunzip [-cfhLrtvVM] [name...]

Catenate compressed files:

    zcat [-hLV] [name...]


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.
Force compression or decompression even if the file has multiple links or the corresponding file already exists. If -f is not given, and when not running in the background, gzip prompts to verify whether an existing file should be overwritten.
Display a help message.
Display the gzip license.
Suppress all warnings.
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 ).
Test. Check the compressed file integrity.
Verbose. Display the name and percentage reduction for each file compressed.
Version. Display the version number and compilation options.
Regulate the speed of compression using the specified digit n, where -1 (the number one) or -fast indicates the fastest compression method (less compression) and -9 or -best indicates the slowest compression method (optimal compression). The default compression level is -5...


The gzip utility 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. If no files are specified, the standard input is compressed to the standard output. If the new file name is too long, gzip truncates it and keeps the original file name in the compressed file. The gzip utility will attempt to compress only regular files. In particular, it will ignore symbolic links.

Compressed files can be restored to their original form using gzip -d or gunzip or zcat.

The gunzip utility takes a list of files on its command line and replaces each file whose name ends with .gz or .GZ 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 or .tar.GZ.

The gunzip utility can currently decompress files created by gzip, zip, compress 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 compress format was not designed to allow consistency checks. However gunzip is sometimes able to detect a bad .GZ file. If you get an error when uncompressing a .GZ file, do not assume that the .GZ 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.

Files created by zip can be uncompressed by gzip only if they have a single member compressed with the "deflation" method. This feature is intended only to help conversion of tar.zip files to the tar.gz format. To extract zip files with several members, obtain and use unzip instead of gunzip. (Note that unzip is not shipped as part of QNX.)

The zcat utility is identical to gunzip -c. The zcat utility 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.

The gzip utility 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 for every 32K block, or an expansion ratio of 0.015% for large files. The gzip utility preserves the mode, ownership and timestamps of files when compressing or decompressing.

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


   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:

   zcat old.gz | gzip > new.gz

Environment variables:

The environment variable GZIP can hold a set of default options for gzip. These options are interpreted first and can be overridden by explicit command line parameters. For example:

    GZIP="-8 -v"; export GZIP

Exit status:

The operation succeeded but perhaps not 100%; a warning was generated in the process.
An error occurred; the operation failed.
The operation succeeded.

Contributing author:



The .gz extension is already also used by UNIX pack. You can link gzip to pcat to get transparent decompression for programs expecting .gz files to be in pack format.

See also:

pax, freeze

[Previous] [Contents] [Next]