1.\" $OpenBSD: compress.1,v 1.43 2009/04/18 18:21:54 naddy Exp $ 2.\" $NetBSD: compress.1,v 1.5 1995/03/26 09:44:34 glass Exp $ 3.\" 4.\" Copyright (c) 1986, 1990, 1993 5.\" The Regents of the University of California. All rights reserved. 6.\" 7.\" This code is derived from software contributed to Berkeley by 8.\" James A. Woods, derived from original work by Spencer Thomas 9.\" and Joseph Orost. 10.\" 11.\" Redistribution and use in source and binary forms, with or without 12.\" modification, are permitted provided that the following conditions 13.\" are met: 14.\" 1. Redistributions of source code must retain the above copyright 15.\" notice, this list of conditions and the following disclaimer. 16.\" 2. Redistributions in binary form must reproduce the above copyright 17.\" notice, this list of conditions and the following disclaimer in the 18.\" documentation and/or other materials provided with the distribution. 19.\" 3. Neither the name of the University nor the names of its contributors 20.\" may be used to endorse or promote products derived from this software 21.\" without specific prior written permission. 22.\" 23.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 24.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 25.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 26.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 27.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 28.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 29.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 30.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 31.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 32.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 33.\" SUCH DAMAGE. 34.\" 35.\" @(#)compress.1 8.2 (Berkeley) 4/18/94 36.\" 37.Dd $Mdocdate: April 18 2009 $ 38.Dt COMPRESS 1 39.Os 40.Sh NAME 41.Nm compress , 42.Nm uncompress , 43.Nm zcat 44.Nd compress and expand data (compress mode) 45.Sh SYNOPSIS 46.Nm compress 47.Op Fl 123456789cdfghLlNnOqrtVv 48.Op Fl b Ar bits 49.Op Fl o Ar filename 50.Op Fl S Ar suffix 51.Op Ar 52.Nm uncompress 53.Op Fl cfhlNnqrtVv 54.Op Fl o Ar filename 55.Op Ar 56.Nm zcat 57.Op Fl fghqr 58.Op Ar 59.Sh DESCRIPTION 60The 61.Nm 62utility 63reduces the size of the named files using adaptive Lempel-Ziv coding, 64in compress mode. 65If invoked as 66.Nm compress Fl g , 67the deflate mode of compression is chosen; 68see 69.Xr gzip 1 70for more information. 71Each file is renamed to the same name plus the extension 72.Dq .Z . 73As many of the modification time, access time, file flags, file mode, 74user ID, and group ID as allowed by permissions are retained in the 75new file. 76If compression would not reduce the size of a file, 77the file is ignored (unless 78.Fl f 79is used). 80.Pp 81The 82.Nm uncompress 83utility restores compressed files to their original form, renaming the 84files by removing the extension (or by using the stored name if the 85.Fl N 86flag is specified). 87It has the ability to restore files compressed by both 88.Nm 89and 90.Xr gzip 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 . 105Extensions ending in 106.Dq tgz 107and 108.Dq taz 109are not removed when decompressing, instead they are converted to 110.Dq tar . 111.Pp 112The 113.Nm zcat 114command is equivalent in functionality to 115.Nm uncompress 116.Fl c . 117.Pp 118If renaming the files would cause files to be overwritten and the standard 119input device is a terminal, the user is prompted (on the standard error 120output) for confirmation. 121If prompting is not possible or confirmation is not received, the files 122are not overwritten. 123.Pp 124If no files are specified, the standard input is compressed or uncompressed 125to the standard output. 126If either the input or output files are not regular files, the checks for 127reduction in size and file overwriting are not performed, the input file is 128not removed, and the attributes of the input file are not retained. 129.Pp 130By default, when compressing using the deflate scheme 131.Pf ( Fl g ) , 132the original file name and time stamp are stored in the compressed file. 133When uncompressing, this information is not used. 134Instead, the uncompressed file inherits the time stamp of the 135compressed version and the uncompressed file name is generated from 136the name of the compressed file as described above. 137These defaults may be overridden by the 138.Fl N 139and 140.Fl n 141flags, described below. 142.Pp 143The options are as follows: 144.Bl -tag -width Ds 145.It Fl 1...9 146Use the deflate scheme, with compression factor of 147.Fl 1 148to 149.Fl 9 . 150Compression factor 151.Fl 1 152is the fastest, but provides a poorer level of compression. 153Compression factor 154.Fl 9 155provides the best level of compression, but is relatively slow. 156The default is 157.Fl 6 . 158This option implies 159.Fl g . 160.It Fl b Ar bits 161Specify the 162.Ar bits 163code limit 164.Pq see below . 165.It Fl c 166Compressed or uncompressed output is written to the standard output. 167No files are modified (force 168.Nm zcat 169mode). 170.It Fl d 171Decompress the source files instead of compressing them (force 172.Nm uncompress 173mode). 174.It Fl f 175Force compression of 176.Ar file , 177even if it is not actually reduced in size. 178Additionally, files are overwritten without prompting for confirmation. 179If the input data is not in a format recognized by 180.Nm 181and if the option 182.Fl c 183is also given, copy the input data without change 184to the standard output: let 185.Nm zcat 186behave as 187.Xr cat 1 . 188.It Fl g 189Use the deflate scheme, which reportedly provides better compression rates 190(force 191.Xr gzip 1 192mode). 193.It Fl h 194Print a short help message. 195.It Fl L 196Print the 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. 232This information is only available when the deflate scheme 233.Pf ( Fl g ) 234is used. 235.It Fl n 236When compressing, do not store the original file name and time stamp 237in the header of the compressed file. 238.It Fl O 239Use compress mode 240(the default). 241.It Fl o Ar filename 242Set the output file name. 243.It Fl q 244Be quiet: suppress all messages. 245.It Fl r 246Recursive mode: 247.Nm 248will descend into specified directories. 249.It Fl S Ar suffix 250Set the suffix for compressed files. 251.It Fl t 252Test the integrity of each file leaving any files intact. 253.It Fl V 254Display the program version 255.Pq RCS IDs of the source files 256and exit. 257.It Fl v 258Print the percentage reduction of each file and other information. 259.El 260.Pp 261.Nm 262uses a modified Lempel-Ziv algorithm 263.Pq LZW . 264Common substrings in the file are first replaced by 9-bit codes 257 and up. 265When code 512 is reached, the algorithm switches to 10-bit codes and 266continues to use more bits until the 267limit specified by the 268.Fl b 269flag is reached. 270.Ar bits 271must be between 9 and 16 272.Pq the default is 16 . 273.Pp 274After the 275.Ar bits 276limit is reached, 277.Nm 278periodically checks the compression ratio. 279If it is increasing, 280.Nm 281continues to use the existing code dictionary. 282However, if the compression ratio decreases, 283.Nm 284discards the table of substrings and rebuilds it from scratch. 285This allows the algorithm to adapt to the next 286.Dq block 287of the file. 288.Pp 289The 290.Fl b 291flag is omitted for 292.Nm uncompress 293since the 294.Ar bits 295parameter specified during compression 296is encoded within the output, along with 297a magic number to ensure that neither decompression of random data nor 298recompression of compressed data is attempted. 299.Pp 300The amount of compression obtained depends on the size of the 301input, the number of 302.Ar bits 303per code, and the distribution of common substrings. 304Typically, text such as source code or English is reduced by 50 \- 60% using 305.Nm . 306Compression is generally much better than that achieved by Huffman 307coding (as used in the historical command pack), or adaptive Huffman 308coding (as used in the historical command compact), and takes less 309time to compute. 310.Pp 311The 312.Nm compress , 313.Nm uncompress , 314and 315.Nm zcat 316utilities exit with 0 on success; 1 if an error occurred; 317or 2 if a warning occurred. 318.Sh SEE ALSO 319.Xr gzexe 1 , 320.Xr gzip 1 , 321.Xr zdiff 1 , 322.Xr zforce 1 , 323.Xr zmore 1 , 324.Xr znew 1 , 325.Xr compress 3 326.Pp 327.Rs 328.%A Welch, Terry A. 329.%D June, 1984 330.%T "A Technique for High Performance Data Compression" 331.%J "IEEE Computer" 332.%V 17:6 333.%P pp. 8\-19 334.Re 335.Sh STANDARDS 336The 337.Nm , 338.Nm uncompress , 339and 340.Nm zcat 341utilities are compliant with the 342.St -xpg4 343specification. 344.Pp 345The 346.Nm 347flags 348.Op Fl 123456789dghLlNnOoqrStV , 349.Nm uncompress 350flags 351.Op Fl hlNnoqrt , 352and the 353.Nm zcat 354flags 355.Op Fl fghqr 356are extensions to that specification. 357.Sh HISTORY 358The 359.Nm 360command appeared in 361.Bx 4.3 . 362Deflate compression support was added in 363.Ox 2.1 . 364