1.\" $OpenBSD: gzip.1,v 1.16 2022/10/22 14:41:27 millert 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 22 2022 $ 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 123456789cdfhkLlNnOqrtVv 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 cfhkLlNnqrtVv 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 87.Nm , 88.Xr compress 1 , 89and 90.Xr zip 1 , 91recognising the following extensions: 92.Dq .Z , 93.Dq -Z , 94.Dq _Z , 95.Dq .gz , 96.Dq -gz , 97.Dq _gz , 98.Dq .tgz , 99.Dq -tgz , 100.Dq _tgz , 101.Dq .taz , 102.Dq -taz , 103and 104.Dq _taz . 105The 106.Fl S 107option can be used to support other file extensions. 108Extensions ending in 109.Dq tgz 110and 111.Dq taz 112are not removed when decompressing, instead they are converted to 113.Dq tar . 114Files in zip format are only supported if they contain a single member 115either compressed with the deflate scheme or stored uncompressed. 116.Pp 117The 118.Nm gzcat 119command is equivalent in functionality to 120.Nm gunzip 121.Fl c . 122.Pp 123If renaming the files would cause files to be overwritten and the standard 124input device is a terminal, the user is prompted (on the standard error 125output) for confirmation. 126If prompting is not possible or confirmation is not received, the files 127are not overwritten. 128.Pp 129If no files are specified, the standard input is compressed or uncompressed 130to the standard output. 131If either the input or output files are not regular files, the checks for 132reduction in size and file overwriting are not performed, the input file is 133not removed, and the attributes of the input file are not retained. 134.Pp 135By default, when compressing, the original file name and time stamp 136are stored in the compressed file. 137When uncompressing, this information is not used. 138Instead, the uncompressed file inherits the time stamp of the 139compressed version and the uncompressed file name is generated from 140the name of the compressed file as described above. 141These defaults may be overridden by the 142.Fl N 143and 144.Fl n 145flags, described below. 146.Pp 147The options are as follows: 148.Bl -tag -width Ds 149.It Fl 1...9 150Use the deflate scheme, with compression factor of 151.Fl 1 152to 153.Fl 9 . 154Compression factor 155.Fl 1 156is the fastest, but provides a poorer level of compression. 157Compression factor 158.Fl 9 159provides the best level of compression, but is relatively slow. 160The default is 161.Fl 6 . 162.It Fl b Ar bits 163Specify the 164.Ar bits 165code limit 166.Pq see below . 167.It Fl c 168Compressed or uncompressed output is written to the standard output. 169No files are modified (force 170.Nm gzcat 171mode). 172.It Fl d 173Decompress the source files instead of compressing them (force 174.Nm gunzip 175mode). 176.It Fl f 177Force compression of 178.Ar file , 179even if it is not actually reduced in size. 180Additionally, files are overwritten without prompting for confirmation. 181If the input data is not in a format recognized by 182.Nm 183and if the option 184.Fl c 185is also given, copy the input data without change 186to the standard output: let 187.Nm gzcat 188behave as 189.Xr cat 1 . 190.It Fl h 191Print a short help message. 192.It Fl k 193Keep input files after compression or decompression. 194.It Fl L 195A no-op which exists for compatibility only. 196On GNU gzip, it displays the program's license. 197.It Fl l 198List information for the specified compressed files. 199The following information is listed: 200.Bl -tag -width "compression ratio" 201.It compressed size 202Size of the compressed file. 203.It uncompressed size 204Size of the file when uncompressed. 205.It compression ratio 206Ratio of the difference between the compressed and uncompressed 207sizes to the uncompressed size. 208.It uncompressed name 209Name the file will be saved as when uncompressing. 210.El 211.Pp 212If the 213.Fl v 214option is specified, the following additional information is printed: 215.Bl -tag -width "compression method" 216.It compression method 217Name of the method used to compress the file. 218.It crc 21932-bit CRC 220.Pq cyclic redundancy code 221of the uncompressed file. 222.It "time stamp" 223Date and time corresponding to the last data modification time 224(mtime) of the compressed file (if the 225.Fl n 226option is specified, the time stamp stored in the compressed file 227is printed instead). 228.El 229.It Fl N 230When uncompressing or listing, use the time stamp and file name stored 231in the compressed file, if any, for the uncompressed version. 232.It Fl n 233When compressing, do not store the original file name and time stamp 234in the 235.Nm 236header. 237.It Fl O 238Use old compression method 239(force 240.Xr compress 1 241mode). 242.It Fl o Ar filename 243Set the output file name. 244.It Fl q 245Be quiet: suppress all messages. 246.It Fl r 247Recursive mode: 248.Nm 249will descend into specified directories. 250.It Fl S Ar suffix 251When compressing, use the specified 252.Ar suffix 253as the extension when creating output files. 254When uncompressing, recognize file names with the specified 255.Ar suffix 256as compressed files. 257.It Fl t 258Test the integrity of each file leaving any files intact. 259.It Fl V 260A no-op which exists for compatibility only. 261On GNU gzip, it displays version information. 262.It Fl v 263Print the percentage reduction of each file and other information. 264.El 265.Pp 266.Nm 267uses a modified Lempel-Ziv algorithm 268.Pq LZW . 269Common substrings are replaced by pointers to previous strings, 270and are found using a hash table. 271Unique substrings are emitted as a string of literal bytes, 272and compressed as Huffman trees. 273When code 512 is reached, the algorithm switches to 10-bit codes and 274continues to use more bits until the 275limit specified by the 276.Fl b 277flag is reached. 278.Ar bits 279must be between 9 and 16 280.Pq the default is 16 . 281.Pp 282After the 283.Ar bits 284limit is reached, 285.Nm 286periodically checks the compression ratio. 287If it is increasing, 288.Nm 289continues to use the existing code dictionary. 290However, if the compression ratio decreases, 291.Nm 292discards the table of substrings and rebuilds it from scratch. 293This allows the algorithm to adapt to the next 294.Dq block 295of the file. 296.Pp 297The 298.Fl b 299flag is omitted for 300.Nm gunzip 301since the 302.Ar bits 303parameter specified during compression 304is encoded within the output, along with 305a magic number to ensure that neither decompression of random data nor 306recompression of compressed data is attempted. 307.Pp 308The amount of compression obtained depends on the size of the 309input, the number of 310.Ar bits 311per code, and the distribution of common substrings. 312Typically, text such as source code or English is reduced by 60 \- 70% using 313.Nm . 314Compression is generally much better than that achieved by Huffman 315coding (as used in the historical command pack), or adaptive Huffman 316coding (as used in the historical command compact), and takes less 317time to compute. 318.Sh ENVIRONMENT 319.Bl -tag -width Ds 320.It Ev GZIP 321Options which are passed to 322.Nm , 323.Nm gunzip , 324and 325.Nm gzcat 326automatically. 327.El 328.Sh EXIT STATUS 329The 330.Nm gzip 331utility exits with one of the following values: 332.Pp 333.Bl -tag -width Ds -offset indent -compact 334.It 0 335Success. 336.It 1 337An error occurred. 338.It 2 339At least one of the specified files was not compressed since 340.Fl f 341was not specified and compression would have resulted in a size 342increase. 343.It \*(Gt2 344An error occurred. 345.El 346.Pp 347The 348.Nm gunzip 349and 350.Nm gzcat 351utilities exit 0 on success, 352and >0 if an error occurs. 353.Sh SEE ALSO 354.Xr compress 1 , 355.Xr gzexe 1 , 356.Xr zdiff 1 , 357.Xr zforce 1 , 358.Xr zmore 1 , 359.Xr znew 1 , 360.Xr compress 3 361.Sh STANDARDS 362.Rs 363.%A P. Deutsch 364.%A J-L. Gailly 365.%D May 1996 366.%R RFC 1950 367.%T ZLIB Compressed Data Format Specification version 3.3 368.Re 369.Pp 370.Rs 371.%A P. Deutsch 372.%D May 1996 373.%R RFC 1951 374.%T DEFLATE Compressed Data Format Specification version 1.3 375.Re 376.Pp 377.Rs 378.%A P. Deutsch 379.%D May 1996 380.%R RFC 1952 381.%T GZIP file format specification version 4.3 382.Re 383.Sh HISTORY 384.Nm gzip 385compatibility was added to 386.Xr compress 1 387in 388.Ox 3.4 . 389The 390.Sq g 391in this version of 392.Nm gzip 393stands for 394.Dq gratis . 395