compress and expand data (compress mode)
utility reduces the size of the named
files using adaptive Lempel-Ziv coding, in compress mode. If invoked as
deflate mode of compression is chosen; see
for more information. Each
file is renamed to the same name plus the extension “.Z”. As
many of the modification time, access 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
utility restores compressed files to
their original form, renaming the files by removing the extension (or by using
the stored name if the -N
flag is specified). It
has the ability to restore files compressed by both
, recognising the following
extensions: “.Z”, “-Z”, “_Z”,
“.gz”, “-gz”, “_gz”,
“.tgz”, “-tgz”, “_tgz”,
“.taz”, “-taz”, and “_taz”.
Extensions ending in “tgz” and “taz” are not
removed when decompressing, instead they are converted to “tar”.
command is equivalent in functionality to
If renaming the files would cause files to be overwritten and the standard input
device is a terminal, the user is prompted (on the standard 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 or uncompressed to
the standard output. If either the input or output files are not regular
files, the checks for reduction in size and file overwriting are not
performed, the input file is not removed, and the attributes of the input file
are not retained.
By default, when compressing using the deflate scheme
), the original file name and time stamp are
stored in the compressed file. When uncompressing, this information is not
used. Instead, the uncompressed file inherits the time stamp of the compressed
version and the uncompressed file name is generated from the name of the
compressed file as described above. These defaults may be overridden by the
The options are as follows:
- Use the deflate scheme, with compression factor of
-1 to -9.
Compression factor -1 is the fastest, but
provides a poorer level of compression. Compression factor
-9 provides the best level of compression,
but is relatively slow. The default is -6.
This option implies -g.
- Specify the bits code
limit (see below).
- Compressed or uncompressed output is written to the
standard output. No files are modified (force
- Decompress the source files instead of compressing them
(force uncompress mode).
- Force compression of file,
even if it is not actually reduced in size. Additionally, files are
overwritten without prompting for confirmation. If the input data is not
in a format recognized by compress and if the
option -c is also given, copy the input data
without change to the standard output: let
zcat behave as
- Use the deflate scheme, which reportedly provides better
compression rates (force
- Print a short help message.
- List information for the specified compressed files. The
following information is listed:
If the -v option is specified, the following
additional information is printed:
- compressed size
- Size of the compressed file.
- uncompressed size
- Size of the file when uncompressed.
- compression ratio
- Ratio of the difference between the compressed and
uncompressed sizes to the uncompressed size.
- uncompressed name
- Name the file will be saved as when uncompressing.
- compression method
- Name of the method used to compress the file.
- 32-bit CRC (cyclic redundancy code) of the uncompressed
- time stamp
- Date and time corresponding to the last data
modification time (mtime) of the compressed file (if the
-n option is specified, the time stamp
stored in the compressed file is printed instead).
- When uncompressing or listing, use the time stamp and file
name stored in the compressed file, if any, for the uncompressed version.
This information is only available when the deflate scheme
(-g) is used.
- When compressing, do not store the original file name and
time stamp in the header of the compressed file.
- Use compress mode (the default).
- Set the output file name.
- Be quiet: suppress all messages.
- Recursive mode: compress will
descend into specified directories.
- Set the suffix for compressed files.
- Test the integrity of each file leaving any files
- Print the percentage reduction of each file and other
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
flag is reached.
must be between 9 and 16 (the default is
After the bits
limit is reached,
periodically checks the compression
ratio. If it is increasing, compress
use the existing code dictionary. However, if the compression ratio decreases,
discards the table of substrings and
rebuilds it from scratch. This allows the algorithm to adapt to the next
“block” of the file.
flag is omitted for
parameter 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
The amount of compression obtained depends on the size of the input, the number
per code, and the distribution of
common substrings. Typically, text such as source code or English is reduced
by 50 - 60% using compress
. Compression is
generally much better than that achieved by Huffman coding (as used in the
historical command pack), or adaptive Huffman coding (as used in the
historical command compact), and takes less time to compute.
utility exits with one of the
- An error occurred.
- At least one of the specified files was not compressed
since -f was not specified and compression
would have resulted in a size increase.
- An error occurred.
utilities exit 0 on success,
and >0 if an error occurs.
Welch, Terry A.,
A Technique for High Performance Data Compression,
IEEE Computer, 17:6,
pp. 8-19, June, 1984.
, and zcat
utilities are compliant with the X/Open System Interfaces option of the
IEEE Std 1003.1-2008
], and the
] are extensions
to that specification.
IEEE Std 1003.1-2008
specifies a maximum bits limit
) of 14 to “achieve portability to all
command appeared in
. Deflate compression support was added in