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