[Previous] [Contents] [Index] [Next]

gzip

Compress or expand files (UNIX)

Syntax:

Compress/uncompress files:

gzip [-cdfhLlNnqrtVv19] [-S suffix] [name...]

Uncompress only:

gunzip [-cfhLlNnqrtvV] [name...]

Cat compressed file:

zcat [-hLV] [name...]

Options:

-c
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.
-f
Force compression or decompression even if the file has multiple links or the corresponding file already exists. If -f isn't given, and when not running in the background, gzip prompts to verify whether an existing file should be overwritten.
-h
Display a help message.
-L
Display the gzip license.
-l
List compressed file contents.
-N
Save or restore the original name and timestamp.
-n
Don't save or restore the original name and timestamp.
-q
Suppress all warnings.
-r
Travel the directory structure recursively. If any of the file names specified on the command line are directories, gzip descends into the directory and compresses all the files it finds there (or decompresses them in the case of gunzip).
-S suffix
Use the given suffix on compressed files.
-t
Test. Check the compressed file integrity.
-V
Version. Display the version number and compilation options.
-v
Verbose. Display the name and percentage reduction for each file compressed.
-1
-9
Regulate the speed of compression, where -1 (the number one) indicates the fastest compression method (less compression) and -9 indicates the slowest compression method (optimal compression).

Description:

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. (The extension is -z for VMS, z for MSDOS, OS/2 and Atari.) 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 attempts to compress only regular files. In particular, it ignores symbolic links.

You can use gzip -d, gunzip, or zcat to restore compressed files to their original form.

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. This utility 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 wasn't 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, don't assume that the .GZ file is correct just because the standard uncompress doesn't complain. This generally means that the standard uncompress doesn't check its input, and happily generates garbage output.

You can use gzip to uncompress files created by zip 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 isn't shipped as part of QNX Neutrino.)

The zcat utility is identical to gunzip -c. (On some systems, zcat may be installed as gzcat to preserve the original link to compress.) 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. It uncompresses 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 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.

You can concatenate multiple compressed files. In this case, gunzip extracts 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:

zcat old.gz | gzip > new.gz

Environment variables:

GZIP
A set of default options for gzip. These options are interpreted first and can be overwritten by explicit command line parameters. For example:
export GZIP="-8 -v"

Exit status:

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

Author:

GNU

Caveats:

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:

bzip2, freeze, pax, tar

Backing Up and Recovering Data in the Neutrino User's Guide


[Previous] [Contents] [Index] [Next]