xref: /openbsd/usr.bin/compress/gzip.1 (revision a6445c1d)
1.\"	$OpenBSD: gzip.1,v 1.14 2014/10/07 21:06:30 deraadt Exp $
2.\"
3.\" Copyright (c) 1986, 1990, 1993
4.\"	The Regents of the University of California.  All rights reserved.
5.\"
6.\" This code is derived from software contributed to Berkeley by
7.\" James A. Woods, derived from original work by Spencer Thomas
8.\" and Joseph Orost.
9.\"
10.\" Redistribution and use in source and binary forms, with or without
11.\" modification, are permitted provided that the following conditions
12.\" are met:
13.\" 1. Redistributions of source code must retain the above copyright
14.\"    notice, this list of conditions and the following disclaimer.
15.\" 2. Redistributions in binary form must reproduce the above copyright
16.\"    notice, this list of conditions and the following disclaimer in the
17.\"    documentation and/or other materials provided with the distribution.
18.\" 3. Neither the name of the University nor the names of its contributors
19.\"    may be used to endorse or promote products derived from this software
20.\"    without specific prior written permission.
21.\"
22.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32.\" SUCH DAMAGE.
33.\"
34.\"     @(#)compress.1	8.2 (Berkeley) 4/18/94
35.\"
36.Dd $Mdocdate: October 7 2014 $
37.Dt GZIP 1
38.Os
39.Sh NAME
40.Nm gzip ,
41.Nm gunzip ,
42.Nm gzcat
43.Nd compress and expand data (deflate mode)
44.Sh SYNOPSIS
45.Nm gzip
46.Op Fl 123456789cdfhLlNnOqrtVv
47.Op Fl b Ar bits
48.Op Fl o Ar filename
49.Op Fl S Ar suffix
50.Op Ar
51.Nm gunzip
52.Op Fl cfhLlNnqrtVv
53.Op Fl o Ar filename
54.Op Ar
55.Nm gzcat
56.Op Fl fhqr
57.Op Ar
58.Sh DESCRIPTION
59The
60.Nm
61utility
62reduces the size of the named files using adaptive Lempel-Ziv coding,
63in deflate mode.
64If invoked as
65.Nm gzip -O ,
66the compress mode of compression is chosen;
67see
68.Xr compress 1
69for more information.
70Each file is renamed to the same name plus the extension
71.Dq .gz .
72As many of the modification time, access time, file flags, file mode,
73user ID, and group ID as allowed by permissions are retained in the
74new file.
75If compression would not reduce the size of a file,
76the file is ignored (unless
77.Fl f
78is used).
79.Pp
80The
81.Nm gunzip
82utility restores compressed files to their original form, renaming the
83files by removing the extension (or by using the stored name if the
84.Fl N
85flag is specified).
86It has the ability to restore files compressed by both
87.Nm
88and
89.Xr compress 1 ,
90recognising the following extensions:
91.Dq .Z ,
92.Dq -Z ,
93.Dq _Z ,
94.Dq .gz ,
95.Dq -gz ,
96.Dq _gz ,
97.Dq .tgz ,
98.Dq -tgz ,
99.Dq _tgz ,
100.Dq .taz ,
101.Dq -taz ,
102and
103.Dq _taz .
104Extensions ending in
105.Dq tgz
106and
107.Dq taz
108are not removed when decompressing, instead they are converted to
109.Dq tar .
110.Pp
111The
112.Nm gzcat
113command is equivalent in functionality to
114.Nm gunzip
115.Fl c .
116.Pp
117If renaming the files would cause files to be overwritten and the standard
118input device is a terminal, the user is prompted (on the standard error
119output) for confirmation.
120If prompting is not possible or confirmation is not received, the files
121are not overwritten.
122.Pp
123If no files are specified, the standard input is compressed or uncompressed
124to the standard output.
125If either the input or output files are not regular files, the checks for
126reduction in size and file overwriting are not performed, the input file is
127not removed, and the attributes of the input file are not retained.
128.Pp
129By default, when compressing, the original file name and time stamp
130are stored in the compressed file.
131When uncompressing, this information is not used.
132Instead, the uncompressed file inherits the time stamp of the
133compressed version and the uncompressed file name is generated from
134the name of the compressed file as described above.
135These defaults may be overridden by the
136.Fl N
137and
138.Fl n
139flags, described below.
140.Pp
141The options are as follows:
142.Bl -tag -width Ds
143.It Fl 1...9
144Use the deflate scheme, with compression factor of
145.Fl 1
146to
147.Fl 9 .
148Compression factor
149.Fl 1
150is the fastest, but provides a poorer level of compression.
151Compression factor
152.Fl 9
153provides the best level of compression, but is relatively slow.
154The default is
155.Fl 6 .
156.It Fl b Ar bits
157Specify the
158.Ar bits
159code limit
160.Pq see below .
161.It Fl c
162Compressed or uncompressed output is written to the standard output.
163No files are modified (force
164.Nm gzcat
165mode).
166.It Fl d
167Decompress the source files instead of compressing them (force
168.Nm gunzip
169mode).
170.It Fl f
171Force compression of
172.Ar file ,
173even if it is not actually reduced in size.
174Additionally, files are overwritten without prompting for confirmation.
175If the input data is not in a format recognized by
176.Nm
177and if the option
178.Fl c
179is also given, copy the input data without change
180to the standard output: let
181.Nm gzcat
182behave as
183.Xr cat 1 .
184.It Fl h
185Print a short help message.
186.It Fl L
187A no-op which exists for compatibility only.
188On GNU gzip, it displays the program's license.
189.It Fl l
190List information for the specified compressed files.
191The following information is listed:
192.Bl -tag -width "compression ratio"
193.It compressed size
194Size of the compressed file.
195.It uncompressed size
196Size of the file when uncompressed.
197.It compression ratio
198Ratio of the difference between the compressed and uncompressed
199sizes to the uncompressed size.
200.It uncompressed name
201Name the file will be saved as when uncompressing.
202.El
203.Pp
204If the
205.Fl v
206option is specified, the following additional information is printed:
207.Bl -tag -width "compression method"
208.It compression method
209Name of the method used to compress the file.
210.It crc
21132-bit CRC
212.Pq cyclic redundancy code
213of the uncompressed file.
214.It "time stamp"
215Date and time corresponding to the last data modification time
216(mtime) of the compressed file (if the
217.Fl n
218option is specified, the time stamp stored in the compressed file
219is printed instead).
220.El
221.It Fl N
222When uncompressing or listing, use the time stamp and file name stored
223in the compressed file, if any, for the uncompressed version.
224.It Fl n
225When compressing, do not store the original file name and time stamp
226in the
227.Nm
228header.
229.It Fl O
230Use old compression method
231(force
232.Xr compress 1
233mode).
234.It Fl o Ar filename
235Set the output file name.
236.It Fl q
237Be quiet: suppress all messages.
238.It Fl r
239Recursive mode:
240.Nm
241will descend into specified directories.
242.It Fl S Ar suffix
243Set the suffix for compressed files.
244.It Fl t
245Test the integrity of each file leaving any files intact.
246.It Fl V
247A no-op which exists for compatibility only.
248On GNU gzip, it displays version information.
249.It Fl v
250Print the percentage reduction of each file and other information.
251.El
252.Pp
253.Nm
254uses a modified Lempel-Ziv algorithm
255.Pq LZW .
256Common substrings are replaced by pointers to previous strings,
257and are found using a hash table.
258Unique substrings are emitted as a string of literal bytes,
259and compressed as Huffman trees.
260When code 512 is reached, the algorithm switches to 10-bit codes and
261continues to use more bits until the
262limit specified by the
263.Fl b
264flag is reached.
265.Ar bits
266must be between 9 and 16
267.Pq the default is 16 .
268.Pp
269After the
270.Ar bits
271limit is reached,
272.Nm
273periodically checks the compression ratio.
274If it is increasing,
275.Nm
276continues to use the existing code dictionary.
277However, if the compression ratio decreases,
278.Nm
279discards the table of substrings and rebuilds it from scratch.
280This allows the algorithm to adapt to the next
281.Dq block
282of the file.
283.Pp
284The
285.Fl b
286flag is omitted for
287.Nm gunzip
288since the
289.Ar bits
290parameter specified during compression
291is encoded within the output, along with
292a magic number to ensure that neither decompression of random data nor
293recompression of compressed data is attempted.
294.Pp
295The amount of compression obtained depends on the size of the
296input, the number of
297.Ar bits
298per code, and the distribution of common substrings.
299Typically, text such as source code or English is reduced by 60 \- 70% using
300.Nm .
301Compression is generally much better than that achieved by Huffman
302coding (as used in the historical command pack), or adaptive Huffman
303coding (as used in the historical command compact), and takes less
304time to compute.
305.Sh ENVIRONMENT
306.Bl -tag -width Ds
307.It Ev GZIP
308Options which are passed to
309.Nm ,
310.Nm gunzip ,
311and
312.Nm gzcat
313automatically.
314.El
315.Sh EXIT STATUS
316The
317.Nm gzip
318utility exits with one of the following values:
319.Pp
320.Bl -tag -width Ds -offset indent -compact
321.It 0
322Success.
323.It 1
324An error occurred.
325.It 2
326At least one of the specified files was not compressed since
327.Fl f
328was not specified and compression would have resulted in a size
329increase.
330.It \*(Gt2
331An error occurred.
332.El
333.Pp
334The
335.Nm gunzip
336and
337.Nm gzcat
338utilities exit 0 on success,
339and >0 if an error occurs.
340.Sh SEE ALSO
341.Xr compress 1 ,
342.Xr gzexe 1 ,
343.Xr zdiff 1 ,
344.Xr zforce 1 ,
345.Xr zmore 1 ,
346.Xr znew 1 ,
347.Xr compress 3
348.Sh STANDARDS
349.Rs
350.%A P. Deutsch
351.%A J-L. Gailly
352.%D May 1996
353.%R RFC 1950
354.%T ZLIB Compressed Data Format Specification version 3.3
355.Re
356.Pp
357.Rs
358.%A P. Deutsch
359.%D May 1996
360.%R RFC 1951
361.%T DEFLATE Compressed Data Format Specification version 1.3
362.Re
363.Pp
364.Rs
365.%A P. Deutsch
366.%D May 1996
367.%R RFC 1952
368.%T GZIP file format specification version 4.3
369.Re
370.Sh HISTORY
371.Nm gzip
372compatibility was added to
373.Xr compress 1
374in
375.Ox 3.4 .
376The
377.Sq g
378in this version of
379.Nm gzip
380stands for
381.Dq gratis .
382