|GZIP(1)||General Commands Manual||GZIP(1)|
gziputility reduces the size of the named files using adaptive Lempel-Ziv coding, in deflate mode. If invoked as
gzip -O, the compress mode of compression is chosen; see compress(1) for more information. Each file is renamed to the same name plus the extension “.gz”. 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
gunzip 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
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”.
gzcat command is equivalent in
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, 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
-n flags, described below.
The options are as follows:
-9. Compression factor
-1is the fastest, but provides a poorer level of compression. Compression factor
-9provides the best level of compression, but is relatively slow. The default is
gzipand if the option
-cis also given, copy the input data without change to the standard output: let
gzcatbehave as cat(1).
-v option is specified, the
following additional information is printed:
-noption is specified, the time stamp stored in the compressed file is printed instead).
gzipwill descend into specified directories.
gzip uses a modified Lempel-Ziv algorithm
(LZW). 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. 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,
gzip periodically checks the compression ratio. If
it is increasing,
gzip continues to use the existing
code dictionary. However, if the compression ratio decreases,
gzip discards the table of substrings and rebuilds
it from scratch. This allows the algorithm to adapt to the next
“block” of the file.
-b flag is omitted for
gunzip since the bits
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 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 60 - 70% using
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.
gziputility exits with one of the following values:
-fwas not specified and compression would have resulted in a size increase.
gzcat utilities exit 0 on success, and >0 if an
P. Deutsch, DEFLATE Compressed Data Format Specification version 1.3, RFC 1951, May 1996.
P. Deutsch, GZIP file format specification version 4.3, RFC 1952, May 1996.
gzipcompatibility was added to compress(1) in OpenBSD 3.4. The ‘g’ in this version of
gzipstands for “gratis”.
|October 7, 2014||OpenBSD-6.1|