compress, uncompress, gzip, gunzip - compress and expand data
compress [-cdfghlOnNqrtv123456789] [-b bits] [-S suffix] [-o
uncompress [-cfhlnNqrtv] [-o filename] [file ...]
gzip [-cdfghlnNOqrtv123456789] [-b bits] [-S suffix] [-o
gunzip [-cfhnNqrltv] [-o filename] [file ...]
zcat [-fghqr] [file ...]
gzcat [-fhqr] [file ...]
The compress and gzip utilities reduce the size of the named
adaptive Lempel-Ziv coding. They are functionally identical, but use
different algorithms for compression. If invoked as gzip or
the deflate mode of compression is chosen by default; otherwise the older
method of compression (compress mode) is used.
Each file is renamed to the same name plus the extension
``.gz'' (in deflate mode). As many of the modification
time, file flags, file mode, user ID, and group ID as allowed by permissions
are retained in the new file. If compression would
not reduce the
size of a file, the file is ignored (unless -f is used).
The uncompress and gunzip utilities restore compressed files
original form, renaming the files by removing the extension
(or by using
the stored name if the -N flag is specified). When decompressing, the
following extensions are recognized: ``.Z'', ``-Z'', ``_Z'',
``-gz'', ``_gz'', ``.tgz'', ``-tgz'', ``_tgz'', ``.taz'',
``_taz''. Extensions ending in ``tgz'' and ``taz'' are not
decompressing, instead they are converted to ``tar''.
The zcat command is equivalent in functionality to
uncompress -c. The
gzcat command is equivalent in functionality to gunzip -c.
If renaming the files would cause files to be overwritten
and the standard
input device is a terminal, the user is prompted (on
error output) for confirmation. If prompting is not possible or confirmation
is not received, the files are not overwritten.
If no files are specified, the standard input is compressed
to the standard output. If either the input or output files are
not regular files, the checks for reduction in size and file
are not performed, the input file is not removed, and the
the input file are not retained.
The options are as follows:
-V Display the program version (RCS IDs of the source
files) and exit.
Specify the bits code limit (see below).
-c Compressed or uncompressed output is written to the
No files are modified (force zcat or gzcat
-d Decompress the source files instead of compressing
-f Force compression of file, even if it is not actually reduced in
size. Additionally, files are overwritten without
confirmation. If the input data is not in a format
compress and if the option -c is also given, copy
the input data
without change to the standard output: let zcat or
-g Use deflate scheme which reportedly provides better
rates (force gzip mode). This flag need not be
invoked as gzip.
-h Print a short help message.
-l List information for the specified compressed files.
information is listed:
compressed size Size of the compressed file.
uncompressed size Size of the file when uncompressed.
compression ratio Ratio of the difference between
and uncompressed sizes to the uncompressed
uncompressed name Name the file will be saved as
If the -v option is specified, the following additional information
compression method Name of the method used to compress the file.
crc 32-bit CRC (cyclic redundancy
code) of the
time stamp Date and time corresponding to
the last data
modification time (mtime) of the
file (if the -n option is specified, the time
stamp stored in the compressed
file is printed
-n When compressing, do not save the original file name
stamp. This information is saved by default when
scheme is used. When uncompressing, do not restore
file name and time stamp. By default, the uncompressed file inherits
the time stamp of the compressed version and
file name is generated from the name of the
file name as described above.
-N When compressing, save the original file name and
time stamp in
the compressed file. This information is saved by
the deflate scheme is used. When uncompressing or
the time stamp and file name stored in the compressed file, if
any, for the uncompressed version.
-1...9 Use deflate scheme with compression factor of -1 to
factor -1 is the fastest, but provides a poorer
compression. Compression factor -9 provides the
best level of
compression, but is relatively slow. The default is
option implies -g.
-O Use old compression method.
Set the output file name.
Set suffix for compressed files.
-t Test the integrity of each file leaving any files
-r Recursive mode, compress will descend into specified
-q Be quiet, suppress all messages.
-v Print the percentage reduction of each file and other information.
In normal mode, compress uses a modified Lempel-Ziv algorithm (LZW).
Common substrings in the file are first replaced by 9-bit
codes 257 and
up. When code 512 is reached, the algorithm switches to
10-bit codes and
continues to use more bits until the limit specified by the
-b flag is
reached. bits must be between 9 and 16 (the default is 16).
After the bits limit is reached, compress periodically
checks the compression
ratio. If it is increasing, compress continues to
use the existing
code dictionary. However, if the compression ratio
compress discards the table of substrings and rebuilds it
This allows the algorithm to adapt to the next ``block'' of
gzip uses a slightly different version of the Lempel-Ziv algorithm
(LZ77). Common substrings are replaced by pointers to previous strings,
and are found using a hash table. Unique substrings are
emitted as a
string of literal bytes, and compressed as Huffman trees.
The -b flag is omitted for uncompress or gunzip since the
specified during compression is encoded within the output,
along with a
magic number to ensure that neither decompression of random
data nor recompression
of compressed data is attempted.
The amount of compression obtained depends on the size of
the input, the
number of bits per code, and the distribution of common substrings. Typically,
text such as source code or English is reduced by 50
- 60% using
compress and by 60 - 70% using gzip. Compression is generally much better
than that achieved by Huffman coding (as used in the
pack), or adaptive Huffman coding (as used in the historical command
compact), and takes less time to compute.
The compress and gzip utilities exit with 0 on success, 1 if
an error occurred,
or 2 if one or more files were not compressed because they would
have grown in size (and -f was not specified).
The compress utility exits with one of the following values:
0 The file was compressed successfully.
1 An error occurred.
2 A warning occurred.
Welch, Terry A., "A Technique for High Performance Data Compression",
IEEE Computer, 17:6, pp. 8-19, June, 1984.
RFC 1950 ZLIB Compressed Data Format Specification.
RFC 1951 DEFLATE Compressed Data Format Specification.
RFC 1952 GZIP File Format Specification.
The compress utility is compliant with the IEEE Std
The gzip and gunzip utilities are extensions.
The compress command appeared in 4.3BSD. The deflate compression support
was added in OpenBSD 2.1. Full gzip compatibility was added
3.4. The `g' in this version of gzip stands for ``gratis''.
OpenBSD 3.6 April 18, 1994
[ Back ]