Initial import from FreeBSD RELENG_4:
[dragonfly.git] / gnu / usr.bin / gzip / gzip.1
1 .\" $FreeBSD: src/gnu/usr.bin/gzip/gzip.1,v 1.7 1999/09/20 09:15:15 phantom Exp $
2 .\"
3 .PU
4 .TH GZIP 1
5 .SH NAME
6 gzip, gunzip, zcat \- compress or expand files
7 .SH SYNOPSIS
8 .ll +8
9 .B gzip
10 .RB [ " \-acdfhlLnNrtvV19 " ]
11 .RB [ \-S\ suffix ]
12 [
13 .I "name \&..."
14 ]
15 .ll -8
16 .br
17 .B gunzip
18 .RB [ " \-acfhlLnNrtvV " ]
19 .RB [ \-S\ suffix ]
20 [
21 .I "name \&..."
22 ]
23 .br
24 .B zcat
25 .RB [ " \-fhLV " ]
26 [
27 .I "name \&..."
28 ]
29 .SH DESCRIPTION
30 .I Gzip
31 reduces the size of the named files using Lempel-Ziv coding (LZ77).
32 Whenever possible,
33 each file is replaced by one with the extension
34 .B "\&.gz,"
35 while keeping the same ownership modes, access and modification times.
36 (The default extension is
37 .B "\-gz"
38 for VMS,
39 .B "z"
40 for MSDOS, OS/2 FAT, Windows NT FAT and Atari.)
41 If no files are specified, or if a file name is "-", the standard input is
42 compressed to the standard output.
43 .I Gzip
44 will only attempt to compress regular files.
45 In particular, it will ignore symbolic links.
46 .PP
47 If the compressed file name is too long for its file system,
48 .I gzip
49 truncates it.
50 .I Gzip
51 attempts to truncate only the parts of the file name longer than 3 characters.
52 (A part is delimited by dots.) If the name consists of small parts only,
53 the longest parts are truncated. For example, if file names are limited
54 to 14 characters, gzip.msdos.exe is compressed to gzi.msd.exe.gz.
55 Names are not truncated on systems which do not have a limit on file name
56 length.
57 .PP
58 By default,
59 .I gzip
60 keeps the original file name and timestamp in the compressed file. These
61 are used when decompressing the file with the
62 .B \-N
63 option. This is useful when the compressed file name was truncated or
64 when the time stamp was not preserved after a file transfer.
65 .PP
66 Compressed files can be restored to their original form using
67 .I gzip -d
68 or
69 .I gunzip
70 or
71 .I zcat.
72 If the original name saved in the compressed file is not suitable for its
73 file system, a new name is constructed from the original one to make it
74 legal.
75 .PP
76 .I gunzip
77 takes a list of files on its command line and replaces each
78 file whose name ends with .gz, -gz, .z, -z, _z or .Z
79 and which begins with the correct magic number with an uncompressed
80 file without the original extension.
81 .I gunzip
82 also recognizes the special extensions
83 .B "\&.tgz"
84 and
85 .B "\&.taz"
86 as shorthands for
87 .B "\&.tar.gz"
88 and
89 .B "\&.tar.Z"
90 respectively.
91 When compressing,
92 .I gzip
93 uses the
94 .B "\&.tgz"
95 extension if necessary instead of truncating a file with a
96 .B "\&.tar"
97 extension.
98 .PP
99 .I gunzip
100 can currently decompress files created by
101 .I gzip, zip, compress, compress -H
102 or
103 .I pack.
104 The detection of the input format is automatic.  When using
105 the first two formats,
106 .I gunzip
107 checks a 32 bit CRC. For
108 .I pack, gunzip
109 checks the uncompressed length. The standard
110 .I compress
111 format was not designed to allow consistency checks. However
112 .I gunzip
113 is sometimes able to detect a bad .Z file. If you get an error
114 when uncompressing a .Z file, do not assume that the .Z file is
115 correct simply because the standard
116 .I uncompress
117 does not complain. This generally means that the standard
118 .I uncompress
119 does not check its input, and happily generates garbage output.
120 The SCO compress -H format (lzh compression method) does not include a CRC
121 but also allows some consistency checks.
122 .PP
123 Files created by
124 .I zip
125 can be uncompressed by gzip only if they have a single member compressed
126 with the 'deflation' method. This feature is only intended to help
127 conversion of tar.zip files to the tar.gz format. To extract zip files
128 with several members, use
129 .I unzip
130 instead of
131 .I gunzip.
132 .PP
133 .I zcat
134 is identical to
135 .I gunzip
136 .B \-c.
137 (On some systems,
138 .I zcat
139 may be installed as
140 .I gzcat
141 to preserve the original link to
142 .I compress.)
143 .I zcat
144 uncompresses either a list of files on the command line or its
145 standard input and writes the uncompressed data on standard output.
146 .I zcat
147 will uncompress files that have the correct magic number whether
148 they have a
149 .B "\&.gz"
150 suffix or not.
151 .PP
152 .I Gzip
153 uses the Lempel-Ziv algorithm used in
154 .I zip
155 and PKZIP.
156 The amount of compression obtained depends on the size of the
157 input and the distribution of common substrings.
158 Typically, text such as source code or English
159 is reduced by 60\-70%.
160 Compression is generally much better than that achieved by
161 LZW (as used in 
162 .IR compress ),
163 Huffman coding (as used in
164 .IR pack ),
165 or adaptive Huffman coding
166 .RI ( compact ).
167 .PP
168 Compression is always performed, even if the compressed file is
169 slightly larger than the original. The worst case expansion is
170 a few bytes for the gzip file header, plus 5 bytes every 32K block,
171 or an expansion ratio of 0.015% for large files. Note that the actual
172 number of used disk blocks almost never increases.
173 .I gzip
174 preserves the mode, ownership and timestamps of files when compressing
175 or decompressing.
176
177 .SH OPTIONS
178 .TP
179 .B \-a --ascii
180 ASCII text mode: convert end-of-lines using local conventions. This option
181 is supported only on some non-Unix systems. For MSDOS, CR LF is converted
182 to LF when compressing, and LF is converted to CR LF when decompressing.
183 .TP
184 .B \-c --stdout --to-stdout
185 Write output on standard output; keep original files unchanged.
186 If there are several input files, the output consists of a sequence of
187 independently compressed members. To obtain better compression,
188 concatenate all input files before compressing them.
189 .TP
190 .B \-d --decompress --uncompress
191 Decompress.
192 .TP
193 .B \-f --force
194 Force compression or decompression even if the file has multiple links
195 or the corresponding file already exists, or if the compressed data
196 is read from or written to a terminal. If the input data is not in
197 a format recognized by
198 .I gzip,
199 and if the option --stdout is also given, copy the input data without change
200 to the standard output: let
201 .I zcat
202 behave as
203 .I cat.
204 If
205 .B \-f
206 is not given,
207 and when not running in the background,
208 .I gzip
209 prompts to verify whether an existing file should be overwritten.
210 .TP
211 .B \-h --help
212 Display a help screen and quit.
213 .TP
214 .B \-l --list
215 For each compressed file, list the following fields:
216
217     compressed size: size of the compressed file
218     uncompressed size: size of the uncompressed file
219     ratio: compression ratio (0.0% if unknown)
220     uncompressed_name: name of the uncompressed file
221
222 The uncompressed size is given as -1 for files not in gzip format,
223 such as compressed .Z files. To get the uncompressed size for such a file,
224 you can use:
225
226     zcat file.Z | wc -c
227
228 In combination with the --verbose option, the following fields are also
229 displayed:
230
231     method: compression method
232     crc: the 32-bit CRC of the uncompressed data
233     date & time: time stamp for the uncompressed file
234
235 The compression methods currently supported are deflate, compress, lzh
236 (SCO compress -H) and pack.  The crc is given as ffffffff for a file
237 not in gzip format.
238
239 With --name, the uncompressed name,  date and time  are
240 those stored within the compress file if present.
241
242 With --verbose, the size totals and compression ratio for all files
243 is also displayed, unless some sizes are unknown. With --quiet,
244 the title and totals lines are not displayed.
245 .TP
246 .B \-L --license
247 Display the
248 .I gzip
249 license and quit.
250 .TP
251 .B \-n --no-name
252 When compressing, do not save the original file name and time stamp by
253 default. (The original name is always saved if the name had to be
254 truncated.) When decompressing, do not restore the original file name
255 if present (remove only the
256 .I gzip
257 suffix from the compressed file name) and do not restore the original
258 time stamp if present (copy it from the compressed file). This option
259 is the default when decompressing.
260 .TP
261 .B \-N --name
262 When compressing, always save the original file name and time stamp; this
263 is the default. When decompressing, restore the original file name and
264 time stamp if present. This option is useful on systems which have
265 a limit on file name length or when the time stamp has been lost after
266 a file transfer.
267 .TP
268 .B \-q --quiet
269 Suppress all warnings.
270 .TP
271 .B \-r --recursive
272 Travel the directory structure recursively. If any of the file names
273 specified on the command line are directories, 
274 .I gzip
275 will descend into the directory and compress all the files it finds there
276 (or decompress them in the case of
277 .I gunzip
278 ).
279 .TP
280 .B \-S .suf   --suffix .suf
281 Use suffix .suf instead of .gz. Any suffix can be given, but suffixes
282 other than .z and .gz should be avoided to avoid confusion when files
283 are transferred to other systems.  A null suffix forces gunzip to  try
284 decompression on all given files regardless of suffix, as in:
285
286     gunzip -S "" *       (*.* for MSDOS)
287
288 Previous versions of gzip used
289 the .z suffix. This was changed to avoid a conflict with
290 .IR pack "(1)".
291 .TP
292 .B \-t --test
293 Test. Check the compressed file integrity.
294 .TP
295 .B \-v --verbose
296 Verbose. Display the name and percentage reduction for each file compressed
297 or decompressed.
298 .TP
299 .B \-V --version
300 Version. Display the version number and compilation options then quit.
301 .TP
302 .B \-# --fast --best
303 Regulate the speed of compression using the specified digit
304 .IR # ,
305 where
306 .B \-1
307 or
308 .B \-\-fast
309 indicates the fastest compression method (less compression)
310 and
311 .B \-9
312 or
313 .B \-\-best
314 indicates the slowest compression method (best compression).
315 The default compression level is
316 .BR \-6
317 (that is, biased towards high compression at expense of speed).
318 .SH "ADVANCED USAGE"
319 Multiple compressed files can be concatenated. In this case,
320 .I gunzip
321 will extract all members at once. For example:
322
323       gzip -c file1  > foo.gz
324       gzip -c file2 >> foo.gz
325
326 Then
327       gunzip -c foo
328
329 is equivalent to
330
331       cat file1 file2
332
333 In case of damage to one member of a .gz file, other members can
334 still be recovered (if the damaged member is removed). However,
335 you can get better compression by compressing all members at once:
336
337       cat file1 file2 | gzip > foo.gz
338
339 compresses better than
340
341       gzip -c file1 file2 > foo.gz
342
343 If you want to recompress concatenated files to get better compression, do:
344
345       gzip -cd old.gz | gzip > new.gz
346
347 If a compressed file consists of several members, the uncompressed
348 size and CRC reported by the --list option applies to the last member
349 only. If you need the uncompressed size for all members, you can use:
350
351       gzip -cd file.gz | wc -c
352
353 If you wish to create a single archive file with multiple members so
354 that members can later be extracted independently, use an archiver
355 such as tar or zip. GNU tar supports the -z option to invoke gzip
356 transparently. gzip is designed as a complement to tar, not as a
357 replacement.
358 .SH "ENVIRONMENT"
359 The environment variable
360 .B GZIP
361 can hold a set of default options for
362 .I gzip.
363 These options are interpreted first and can be overwritten by
364 explicit command line parameters. For example:
365       for sh:    GZIP="-8v --name"; export GZIP
366       for csh:   setenv GZIP "-8v --name"
367       for MSDOS: set GZIP=-8v --name
368
369 On Vax/VMS, the name of the environment variable is GZIP_OPT, to
370 avoid a conflict with the symbol set for invocation of the program.
371 .SH "SEE ALSO"
372 znew(1), zcmp(1), zmore(1), zforce(1), gzexe(1), compress(1)
373 .SH "DIAGNOSTICS"
374 Exit status is normally 0;
375 if an error occurs, exit status is 1. If a warning occurs, exit status is 2.
376 .PP
377 Usage: gzip [-cdfhlLnNrtvV19] [-S suffix] [file ...]
378 .in +8
379 Invalid options were specified on the command line.
380 .in -8
381 .IR file :
382 not in gzip format
383 .in +8
384 The file specified to
385 .I gunzip
386 has not been compressed.
387 .in -8
388 .IR file:
389 Corrupt input. Use zcat to recover some data.
390 .in +8
391 The compressed file has been damaged. The data up to the point of failure
392 can be recovered using
393 .in +8
394 zcat file > recover
395 .in -16
396 .IR file :
397 compressed with 
398 .I xx
399 bits, can only handle 
400 .I yy
401 bits
402 .in +8
403 .I File
404 was compressed (using LZW) by a program that could deal with
405 more 
406 .I bits
407 than the decompress code on this machine.
408 Recompress the file with gzip, which compresses better and uses
409 less memory.
410 .in -8
411 .IR file :
412 already has .gz suffix -- no change
413 .in +8
414 The file is assumed to be already compressed.
415 Rename the file and try again.
416 .in -8
417 .I file
418 already exists; do you wish to overwrite (y or n)?
419 .in +8
420 Respond "y" if you want the output file to be replaced; "n" if not.
421 .in -8
422 gunzip: corrupt input
423 .in +8
424 A SIGSEGV violation was detected which usually means that the input file has
425 been corrupted.
426 .in -8
427 .I "xx.x%"
428 .in +8
429 Percentage of the input saved by compression.
430 (Relevant only for
431 .BR \-v
432 and
433 .BR \-l \.)
434 .in -8
435 -- not a regular file or directory: ignored
436 .in +8
437 When the input file is not a regular file or directory,
438 (e.g. a symbolic link, socket, FIFO, device file), it is
439 left unaltered.
440 .in -8
441 -- has 
442 .I xx 
443 other links: unchanged
444 .in +8
445 The input file has links; it is left unchanged.  See
446 .IR ln "(1)"
447 for more information. Use the
448 .B \-f
449 flag to force compression of multiply-linked files.
450 .in -8
451 .SH CAVEATS
452 When writing compressed data to a tape, it is generally necessary to
453 pad the output with zeroes up to a block boundary. When the data is
454 read and the whole block is passed to
455 .I gunzip
456 for decompression,
457 .I gunzip
458 detects that there is extra trailing garbage after the compressed data
459 and emits a warning by default. You have to use the --quiet option to
460 suppress the warning. This option can be set in the
461 .B GZIP
462 environment variable as in:
463   for sh:  GZIP="-q"  tar -xfz --block-compress /dev/rst0
464   for csh: (setenv GZIP -q; tar -xfz --block-compr /dev/rst0
465
466 In the above example, gzip is invoked implicitly by the -z option of
467 GNU tar. Make sure that the same block size (-b option of tar) is used
468 for reading and writing compressed data on tapes.  (This example
469 assumes you are using the GNU version of tar.)
470 .SH BUGS
471 The --list option reports incorrect sizes if they exceed 2 gigabytes.
472 The --list option reports sizes as -1 and crc as ffffffff if the
473 compressed file is on a non seekable media.
474
475 In some rare cases, the --best option gives worse compression than
476 the default compression level (-6). On some highly redundant files,
477 .I compress
478 compresses better than
479 .I gzip.