1*3ab258a1Smillert.\" $OpenBSD: gzip.1,v 1.16 2022/10/22 14:41:27 millert Exp $ 23a68a017Sjmc.\" 33a68a017Sjmc.\" Copyright (c) 1986, 1990, 1993 43a68a017Sjmc.\" The Regents of the University of California. All rights reserved. 53a68a017Sjmc.\" 63a68a017Sjmc.\" This code is derived from software contributed to Berkeley by 73a68a017Sjmc.\" James A. Woods, derived from original work by Spencer Thomas 83a68a017Sjmc.\" and Joseph Orost. 93a68a017Sjmc.\" 103a68a017Sjmc.\" Redistribution and use in source and binary forms, with or without 113a68a017Sjmc.\" modification, are permitted provided that the following conditions 123a68a017Sjmc.\" are met: 133a68a017Sjmc.\" 1. Redistributions of source code must retain the above copyright 143a68a017Sjmc.\" notice, this list of conditions and the following disclaimer. 153a68a017Sjmc.\" 2. Redistributions in binary form must reproduce the above copyright 163a68a017Sjmc.\" notice, this list of conditions and the following disclaimer in the 173a68a017Sjmc.\" documentation and/or other materials provided with the distribution. 183a68a017Sjmc.\" 3. Neither the name of the University nor the names of its contributors 193a68a017Sjmc.\" may be used to endorse or promote products derived from this software 203a68a017Sjmc.\" without specific prior written permission. 213a68a017Sjmc.\" 223a68a017Sjmc.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 233a68a017Sjmc.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 243a68a017Sjmc.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 253a68a017Sjmc.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 263a68a017Sjmc.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 273a68a017Sjmc.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 283a68a017Sjmc.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 293a68a017Sjmc.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 303a68a017Sjmc.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 313a68a017Sjmc.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 323a68a017Sjmc.\" SUCH DAMAGE. 333a68a017Sjmc.\" 343a68a017Sjmc.\" @(#)compress.1 8.2 (Berkeley) 4/18/94 353a68a017Sjmc.\" 36*3ab258a1Smillert.Dd $Mdocdate: October 22 2022 $ 373a68a017Sjmc.Dt GZIP 1 383a68a017Sjmc.Os 393a68a017Sjmc.Sh NAME 403a68a017Sjmc.Nm gzip , 413a68a017Sjmc.Nm gunzip , 423a68a017Sjmc.Nm gzcat 433a68a017Sjmc.Nd compress and expand data (deflate mode) 443a68a017Sjmc.Sh SYNOPSIS 453a68a017Sjmc.Nm gzip 467610cfa0Ssolene.Op Fl 123456789cdfhkLlNnOqrtVv 473a68a017Sjmc.Op Fl b Ar bits 483a68a017Sjmc.Op Fl o Ar filename 493a68a017Sjmc.Op Fl S Ar suffix 503a68a017Sjmc.Op Ar 513a68a017Sjmc.Nm gunzip 527610cfa0Ssolene.Op Fl cfhkLlNnqrtVv 533a68a017Sjmc.Op Fl o Ar filename 543a68a017Sjmc.Op Ar 553a68a017Sjmc.Nm gzcat 569d691d83Smillert.Op Fl fhqr 573a68a017Sjmc.Op Ar 583a68a017Sjmc.Sh DESCRIPTION 593a68a017SjmcThe 603a68a017Sjmc.Nm 613a68a017Sjmcutility 623a68a017Sjmcreduces the size of the named files using adaptive Lempel-Ziv coding, 633a68a017Sjmcin deflate mode. 643a68a017SjmcIf invoked as 653a68a017Sjmc.Nm gzip -O , 663a68a017Sjmcthe compress mode of compression is chosen; 673a68a017Sjmcsee 683a68a017Sjmc.Xr compress 1 693a68a017Sjmcfor more information. 703a68a017SjmcEach file is renamed to the same name plus the extension 713a68a017Sjmc.Dq .gz . 723a68a017SjmcAs many of the modification time, access time, file flags, file mode, 733a68a017Sjmcuser ID, and group ID as allowed by permissions are retained in the 743a68a017Sjmcnew file. 753a68a017SjmcIf compression would not reduce the size of a file, 763a68a017Sjmcthe file is ignored (unless 773a68a017Sjmc.Fl f 783a68a017Sjmcis used). 793a68a017Sjmc.Pp 803a68a017SjmcThe 813a68a017Sjmc.Nm gunzip 823a68a017Sjmcutility restores compressed files to their original form, renaming the 833a68a017Sjmcfiles by removing the extension (or by using the stored name if the 843a68a017Sjmc.Fl N 853a68a017Sjmcflag is specified). 86*3ab258a1SmillertIt has the ability to restore files compressed by 87*3ab258a1Smillert.Nm , 883a68a017Sjmc.Xr compress 1 , 89*3ab258a1Smillertand 90*3ab258a1Smillert.Xr zip 1 , 913a68a017Sjmcrecognising the following extensions: 923a68a017Sjmc.Dq .Z , 933a68a017Sjmc.Dq -Z , 943a68a017Sjmc.Dq _Z , 953a68a017Sjmc.Dq .gz , 963a68a017Sjmc.Dq -gz , 973a68a017Sjmc.Dq _gz , 983a68a017Sjmc.Dq .tgz , 993a68a017Sjmc.Dq -tgz , 1003a68a017Sjmc.Dq _tgz , 1013a68a017Sjmc.Dq .taz , 1023a68a017Sjmc.Dq -taz , 1033a68a017Sjmcand 1043a68a017Sjmc.Dq _taz . 105*3ab258a1SmillertThe 106*3ab258a1Smillert.Fl S 107*3ab258a1Smillertoption can be used to support other file extensions. 1083a68a017SjmcExtensions ending in 1093a68a017Sjmc.Dq tgz 1103a68a017Sjmcand 1113a68a017Sjmc.Dq taz 1123a68a017Sjmcare not removed when decompressing, instead they are converted to 1133a68a017Sjmc.Dq tar . 114*3ab258a1SmillertFiles in zip format are only supported if they contain a single member 115*3ab258a1Smillerteither compressed with the deflate scheme or stored uncompressed. 1163a68a017Sjmc.Pp 1173a68a017SjmcThe 1183a68a017Sjmc.Nm gzcat 1193a68a017Sjmccommand is equivalent in functionality to 1203a68a017Sjmc.Nm gunzip 1213a68a017Sjmc.Fl c . 1223a68a017Sjmc.Pp 1233a68a017SjmcIf renaming the files would cause files to be overwritten and the standard 1243a68a017Sjmcinput device is a terminal, the user is prompted (on the standard error 1253a68a017Sjmcoutput) for confirmation. 1263a68a017SjmcIf prompting is not possible or confirmation is not received, the files 1273a68a017Sjmcare not overwritten. 1283a68a017Sjmc.Pp 1293a68a017SjmcIf no files are specified, the standard input is compressed or uncompressed 1303a68a017Sjmcto the standard output. 1313a68a017SjmcIf either the input or output files are not regular files, the checks for 1323a68a017Sjmcreduction in size and file overwriting are not performed, the input file is 1333a68a017Sjmcnot removed, and the attributes of the input file are not retained. 1343a68a017Sjmc.Pp 1359f9b3673SmillertBy default, when compressing, the original file name and time stamp 1366fdd2a58Sjmcare stored in the compressed file. 1379f9b3673SmillertWhen uncompressing, this information is not used. 1389f9b3673SmillertInstead, the uncompressed file inherits the time stamp of the 1399f9b3673Smillertcompressed version and the uncompressed file name is generated from 1409f9b3673Smillertthe name of the compressed file as described above. 1419f9b3673SmillertThese defaults may be overridden by the 1429f9b3673Smillert.Fl N 1439f9b3673Smillertand 1449f9b3673Smillert.Fl n 1459f9b3673Smillertflags, described below. 1469f9b3673Smillert.Pp 1473a68a017SjmcThe options are as follows: 1483a68a017Sjmc.Bl -tag -width Ds 1493a68a017Sjmc.It Fl 1...9 1503a68a017SjmcUse the deflate scheme, with compression factor of 1513a68a017Sjmc.Fl 1 1523a68a017Sjmcto 1533a68a017Sjmc.Fl 9 . 1543a68a017SjmcCompression factor 1553a68a017Sjmc.Fl 1 1563a68a017Sjmcis the fastest, but provides a poorer level of compression. 1573a68a017SjmcCompression factor 1583a68a017Sjmc.Fl 9 1593a68a017Sjmcprovides the best level of compression, but is relatively slow. 1603a68a017SjmcThe default is 1613a68a017Sjmc.Fl 6 . 1623a68a017Sjmc.It Fl b Ar bits 1633a68a017SjmcSpecify the 1643a68a017Sjmc.Ar bits 1653a68a017Sjmccode limit 1663a68a017Sjmc.Pq see below . 1673a68a017Sjmc.It Fl c 1683a68a017SjmcCompressed or uncompressed output is written to the standard output. 1693a68a017SjmcNo files are modified (force 1703a68a017Sjmc.Nm gzcat 1713a68a017Sjmcmode). 1723a68a017Sjmc.It Fl d 1733a68a017SjmcDecompress the source files instead of compressing them (force 1743a68a017Sjmc.Nm gunzip 1753a68a017Sjmcmode). 1763a68a017Sjmc.It Fl f 1773a68a017SjmcForce compression of 1783a68a017Sjmc.Ar file , 1793a68a017Sjmceven if it is not actually reduced in size. 1803a68a017SjmcAdditionally, files are overwritten without prompting for confirmation. 1813a68a017SjmcIf the input data is not in a format recognized by 1823a68a017Sjmc.Nm 1833a68a017Sjmcand if the option 1843a68a017Sjmc.Fl c 1853a68a017Sjmcis also given, copy the input data without change 1863a68a017Sjmcto the standard output: let 1873a68a017Sjmc.Nm gzcat 1883a68a017Sjmcbehave as 1893a68a017Sjmc.Xr cat 1 . 1903a68a017Sjmc.It Fl h 1913a68a017SjmcPrint a short help message. 1927610cfa0Ssolene.It Fl k 1937610cfa0SsoleneKeep input files after compression or decompression. 1943a68a017Sjmc.It Fl L 19522b9cd92SjmcA no-op which exists for compatibility only. 19622b9cd92SjmcOn GNU gzip, it displays the program's license. 1973a68a017Sjmc.It Fl l 1983a68a017SjmcList information for the specified compressed files. 1993a68a017SjmcThe following information is listed: 2003a68a017Sjmc.Bl -tag -width "compression ratio" 2013a68a017Sjmc.It compressed size 2023a68a017SjmcSize of the compressed file. 2033a68a017Sjmc.It uncompressed size 2043a68a017SjmcSize of the file when uncompressed. 2053a68a017Sjmc.It compression ratio 2063a68a017SjmcRatio of the difference between the compressed and uncompressed 2073a68a017Sjmcsizes to the uncompressed size. 2083a68a017Sjmc.It uncompressed name 2093a68a017SjmcName the file will be saved as when uncompressing. 2103a68a017Sjmc.El 2113a68a017Sjmc.Pp 2123a68a017SjmcIf the 2133a68a017Sjmc.Fl v 2143a68a017Sjmcoption is specified, the following additional information is printed: 2153a68a017Sjmc.Bl -tag -width "compression method" 2163a68a017Sjmc.It compression method 2173a68a017SjmcName of the method used to compress the file. 2183a68a017Sjmc.It crc 2193a68a017Sjmc32-bit CRC 2203a68a017Sjmc.Pq cyclic redundancy code 2213a68a017Sjmcof the uncompressed file. 2223a68a017Sjmc.It "time stamp" 2233a68a017SjmcDate and time corresponding to the last data modification time 2243a68a017Sjmc(mtime) of the compressed file (if the 2253a68a017Sjmc.Fl n 2263a68a017Sjmcoption is specified, the time stamp stored in the compressed file 2273a68a017Sjmcis printed instead). 2283a68a017Sjmc.El 2293a68a017Sjmc.It Fl N 2303a68a017SjmcWhen uncompressing or listing, use the time stamp and file name stored 2313a68a017Sjmcin the compressed file, if any, for the uncompressed version. 2323a68a017Sjmc.It Fl n 2339f9b3673SmillertWhen compressing, do not store the original file name and time stamp 2349f9b3673Smillertin the 2359f9b3673Smillert.Nm 2369f9b3673Smillertheader. 2373a68a017Sjmc.It Fl O 2383a68a017SjmcUse old compression method 2393a68a017Sjmc(force 2403a68a017Sjmc.Xr compress 1 2413a68a017Sjmcmode). 2423a68a017Sjmc.It Fl o Ar filename 2433a68a017SjmcSet the output file name. 2443a68a017Sjmc.It Fl q 2453a68a017SjmcBe quiet: suppress all messages. 2463a68a017Sjmc.It Fl r 2473a68a017SjmcRecursive mode: 2483a68a017Sjmc.Nm 2493a68a017Sjmcwill descend into specified directories. 2503a68a017Sjmc.It Fl S Ar suffix 251*3ab258a1SmillertWhen compressing, use the specified 252*3ab258a1Smillert.Ar suffix 253*3ab258a1Smillertas the extension when creating output files. 254*3ab258a1SmillertWhen uncompressing, recognize file names with the specified 255*3ab258a1Smillert.Ar suffix 256*3ab258a1Smillertas compressed files. 2573a68a017Sjmc.It Fl t 2583a68a017SjmcTest the integrity of each file leaving any files intact. 2593a68a017Sjmc.It Fl V 26022b9cd92SjmcA no-op which exists for compatibility only. 26122b9cd92SjmcOn GNU gzip, it displays version information. 2623a68a017Sjmc.It Fl v 2633a68a017SjmcPrint the percentage reduction of each file and other information. 2643a68a017Sjmc.El 2653a68a017Sjmc.Pp 2663a68a017Sjmc.Nm 2673a68a017Sjmcuses a modified Lempel-Ziv algorithm 2683a68a017Sjmc.Pq LZW . 2693a68a017SjmcCommon substrings are replaced by pointers to previous strings, 2703a68a017Sjmcand are found using a hash table. 2713a68a017SjmcUnique substrings are emitted as a string of literal bytes, 2723a68a017Sjmcand compressed as Huffman trees. 2733a68a017SjmcWhen code 512 is reached, the algorithm switches to 10-bit codes and 2743a68a017Sjmccontinues to use more bits until the 2753a68a017Sjmclimit specified by the 2763a68a017Sjmc.Fl b 2773a68a017Sjmcflag is reached. 2783a68a017Sjmc.Ar bits 2793a68a017Sjmcmust be between 9 and 16 2803a68a017Sjmc.Pq the default is 16 . 2813a68a017Sjmc.Pp 2823a68a017SjmcAfter the 2833a68a017Sjmc.Ar bits 2843a68a017Sjmclimit is reached, 2853a68a017Sjmc.Nm 2863a68a017Sjmcperiodically checks the compression ratio. 2873a68a017SjmcIf it is increasing, 2883a68a017Sjmc.Nm 2893a68a017Sjmccontinues to use the existing code dictionary. 2903a68a017SjmcHowever, if the compression ratio decreases, 2913a68a017Sjmc.Nm 2923a68a017Sjmcdiscards the table of substrings and rebuilds it from scratch. 2933a68a017SjmcThis allows the algorithm to adapt to the next 2943a68a017Sjmc.Dq block 2953a68a017Sjmcof the file. 2963a68a017Sjmc.Pp 2973a68a017SjmcThe 2983a68a017Sjmc.Fl b 2993a68a017Sjmcflag is omitted for 3003a68a017Sjmc.Nm gunzip 3013a68a017Sjmcsince the 3023a68a017Sjmc.Ar bits 3033a68a017Sjmcparameter specified during compression 3043a68a017Sjmcis encoded within the output, along with 3053a68a017Sjmca magic number to ensure that neither decompression of random data nor 3063a68a017Sjmcrecompression of compressed data is attempted. 3073a68a017Sjmc.Pp 3083a68a017SjmcThe amount of compression obtained depends on the size of the 3093a68a017Sjmcinput, the number of 3103a68a017Sjmc.Ar bits 3113a68a017Sjmcper code, and the distribution of common substrings. 3123a68a017SjmcTypically, text such as source code or English is reduced by 60 \- 70% using 3133a68a017Sjmc.Nm . 3143a68a017SjmcCompression is generally much better than that achieved by Huffman 3153a68a017Sjmccoding (as used in the historical command pack), or adaptive Huffman 3163a68a017Sjmccoding (as used in the historical command compact), and takes less 3173a68a017Sjmctime to compute. 318fa9e263bSray.Sh ENVIRONMENT 319fa9e263bSray.Bl -tag -width Ds 320fa9e263bSray.It Ev GZIP 321fa9e263bSrayOptions which are passed to 322fa9e263bSray.Nm , 323fa9e263bSray.Nm gunzip , 324fa9e263bSrayand 325fa9e263bSray.Nm gzcat 326fa9e263bSrayautomatically. 327fa9e263bSray.El 3280e99d2a7Sjmc.Sh EXIT STATUS 3290e99d2a7SjmcThe 330f0c76bcbSsobrado.Nm gzip 331f0c76bcbSsobradoutility exits with one of the following values: 332f0c76bcbSsobrado.Pp 333f0c76bcbSsobrado.Bl -tag -width Ds -offset indent -compact 334f0c76bcbSsobrado.It 0 335f0c76bcbSsobradoSuccess. 336f0c76bcbSsobrado.It 1 337f0c76bcbSsobradoAn error occurred. 338f0c76bcbSsobrado.It 2 339f0c76bcbSsobradoAt least one of the specified files was not compressed since 340f0c76bcbSsobrado.Fl f 341f0c76bcbSsobradowas not specified and compression would have resulted in a size 342f0c76bcbSsobradoincrease. 343f0c76bcbSsobrado.It \*(Gt2 344f0c76bcbSsobradoAn error occurred. 345f0c76bcbSsobrado.El 346f0c76bcbSsobrado.Pp 347f0c76bcbSsobradoThe 348f0c76bcbSsobrado.Nm gunzip 3490e99d2a7Sjmcand 3500e99d2a7Sjmc.Nm gzcat 351f0c76bcbSsobradoutilities exit 0 on success, 352f0c76bcbSsobradoand >0 if an error occurs. 3533a68a017Sjmc.Sh SEE ALSO 3543a68a017Sjmc.Xr compress 1 , 3553a68a017Sjmc.Xr gzexe 1 , 3563a68a017Sjmc.Xr zdiff 1 , 3573a68a017Sjmc.Xr zforce 1 , 3583a68a017Sjmc.Xr zmore 1 , 3593a68a017Sjmc.Xr znew 1 , 3603a68a017Sjmc.Xr compress 3 3616b2bc0edSjmc.Sh STANDARDS 362f85d078bSjmc.Rs 363f85d078bSjmc.%A P. Deutsch 364f85d078bSjmc.%A J-L. Gailly 365f85d078bSjmc.%D May 1996 366f85d078bSjmc.%R RFC 1950 367f85d078bSjmc.%T ZLIB Compressed Data Format Specification version 3.3 368f85d078bSjmc.Re 3696b2bc0edSjmc.Pp 370f85d078bSjmc.Rs 371f85d078bSjmc.%A P. Deutsch 372f85d078bSjmc.%D May 1996 373f85d078bSjmc.%R RFC 1951 374f85d078bSjmc.%T DEFLATE Compressed Data Format Specification version 1.3 375f85d078bSjmc.Re 3766b2bc0edSjmc.Pp 377f85d078bSjmc.Rs 378f85d078bSjmc.%A P. Deutsch 379f85d078bSjmc.%D May 1996 380f85d078bSjmc.%R RFC 1952 381f85d078bSjmc.%T GZIP file format specification version 4.3 382f85d078bSjmc.Re 3833a68a017Sjmc.Sh HISTORY 3843a68a017Sjmc.Nm gzip 3853a68a017Sjmccompatibility was added to 3863a68a017Sjmc.Xr compress 1 3873a68a017Sjmcin 3883a68a017Sjmc.Ox 3.4 . 3893a68a017SjmcThe 3903a68a017Sjmc.Sq g 3913a68a017Sjmcin this version of 3923a68a017Sjmc.Nm gzip 3933a68a017Sjmcstands for 3943a68a017Sjmc.Dq gratis . 395