1.\" Copyright (c) 1986, 1990 The Regents of the University of California. 2.\" All rights reserved. 3.\" 4.\" This code is derived from software contributed to Berkeley by 5.\" James A. Woods, derived from original work by Spencer Thomas 6.\" and Joseph Orost. 7.\" 8.\" Redistribution and use in source and binary forms, with or without 9.\" modification, are permitted provided that the following conditions 10.\" are met: 11.\" 1. Redistributions of source code must retain the above copyright 12.\" notice, this list of conditions and the following disclaimer. 13.\" 2. Redistributions in binary form must reproduce the above copyright 14.\" notice, this list of conditions and the following disclaimer in the 15.\" documentation and/or other materials provided with the distribution. 16.\" 3. All advertising materials mentioning features or use of this software 17.\" must display the following acknowledgement: 18.\" This product includes software developed by the University of 19.\" California, Berkeley and its contributors. 20.\" 4. Neither the name of the University nor the names of its contributors 21.\" may be used to endorse or promote products derived from this software 22.\" without specific prior written permission. 23.\" 24.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 25.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 26.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 27.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 28.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 29.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 30.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 31.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 32.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 33.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 34.\" SUCH DAMAGE. 35.\" 36.\" @(#)compress.1 6.10 (Berkeley) 7/30/91 37.\" 38.Dd July 30, 1991 39.Dt COMPRESS 1 40.Os BSD 4.3 41.Sh NAME 42.Nm compress , 43.Nm uncompress , 44.Nm zcat 45.Nd compress and expand data 46.Sh SYNOPSIS 47.Nm compress 48.Op Fl f 49.Op Fl v 50.Op Fl c 51.Op Fl b Ar bits 52.Op Ar 53.Nm uncompress 54.Op Fl f 55.Op Fl v 56.Op Fl c 57.Ar 58.Nm zcat 59.Op Ar 60.Sh DESCRIPTION 61.Nm Compress 62reduces the size of the named files using adaptive Lempel-Ziv coding. 63Whenever possible, 64each 65.Ar file 66is replaced by one with the extension 67.Ar \&.Z , 68while keeping the same ownership modes, access and modification times. 69If no files are specified, the standard input is compressed to the 70standard output. 71Compressed files can be restored to their original form using 72.Nm uncompress 73or 74.Nm zcat 75.Bl -tag -width Ds 76.It Fl f 77Force compression of 78.Ar file , 79even if it does not actually shrink 80or the corresponding 81.Ar file.Z 82file already exists. 83Except when run in the background under 84.Pa /bin/sh , 85if 86.Fl f 87is not given the user is prompted as to whether an existing 88.Ar file.Z 89file should be overwritten. 90.It Fl c 91(``cat''). 92.Nm Compress/uncompress 93writes to the standard output; no files are changed. 94The nondestructive behavior of 95.Nm zcat 96is identical to that of 97.Nm uncompress 98.Fl c . 99.It Fl b 100Specify 101.Ar bits 102code limit (see below). 103.It Fl v 104Print the percentage reduction of each file. 105.El 106.Pp 107.Nm Compress 108uses the modified Lempel-Ziv algorithm popularized in 109"A Technique for High Performance Data Compression", 110Terry A. Welch, 111.Em IEEE Computer , 112vol. 17, 113.no 6 114(June 1984), pp. 8-19. 115Common substrings in the file are first replaced by 9-bit codes 257 and up. 116When code 512 is reached, the algorithm switches to 10-bit codes and 117continues to use more bits until the 118limit specified by the 119.Fl b 120flag is reached (default 16). 121.Ar Bits 122must be between 9 and 16. The default can be changed in the source to allow 123.Nm compress 124to be run on a smaller machine. 125.Pp 126After the 127.Ar bits 128limit is attained, 129.Nm compress 130periodically checks the compression ratio. If it is increasing, 131.Nm compress 132continues to use the existing code dictionary. However, 133if the compression ratio decreases, 134.Nm compress 135discards the table of substrings and rebuilds it from scratch. This allows 136the algorithm to adapt to the next "block" of the file. 137.Pp 138Note that the 139.Fl b 140flag is omitted for 141.Ar uncompress 142since the 143.Ar bits 144parameter specified during compression 145is encoded within the output, along with 146a magic number to ensure that neither decompression of random data nor 147recompression of compressed data is attempted. 148.Pp 149.ne 8 150The amount of compression obtained depends on the size of the 151input, the number of 152.Ar bits 153per code, and the distribution of common substrings. 154Typically, text such as source code or English 155is reduced by 50\-60%. 156Compression is generally much better than that achieved by 157Huffman coding (as used in the historical command 158pack), 159or adaptive Huffman coding (as 160used in the historical command 161compact), 162and takes less time to compute. 163.Pp 164If an error occurs, exit status is 1; 165if the last file was not compressed because it became larger, the status 166is 2; otherwise the status is 0. 167.Sh DIAGNOSTICS 168.Bl -tag -width flag 169.It "Usage: compress [-fvc] [-b maxbits] [file ...]" 170Invalid options were specified on the command line. 171.It "Missing maxbits" 172Maxbits must follow 173.Fl b . 174.It Ar file : No "not in compressed format" 175The file specified to 176.Ar uncompress 177has not been compressed. 178.It Xo 179.Ar file : No "compressed with" 180.Ar \&xx No "bits, can only handle" 181.Ar \&yy No bits 182.Xc 183.Ar File 184was compressed by a program that could deal with 185more 186.Ar bits 187than the compress code on this machine. 188Recompress the file with smaller 189.Ar bits . 190.It Ar file : No "already has .Z suffix -- no change" 191The file is assumed to be already compressed. 192Rename the file and try again. 193.It Ar file : No "filename too long to tack on .Z" 194The file cannot be compressed because its name is longer than 19512 characters. 196Rename and try again. 197This message does not occur on 198.Bx 199systems. 200.It Ar file No "already exists; do you wish to overwrite (y or n)?" 201Respond "y" if you want the output file to be replaced; "n" if not. 202.It "uncompress: corrupt input" 203A 204.Dv SIGSEGV 205violation was detected which usually means that the input file is 206corrupted. 207.It Compression: Em "xx.xx%" 208Percentage of the input saved by compression. 209(Relevant only for 210.Fl v . ) 211.It "-- not a regular file: unchanged" 212When the input file is not a regular file, 213(e.g. a directory), it is 214left unaltered. 215.It "-- has" Ar xx No "other links: unchanged" 216The input file has links; it is left unchanged. See 217.Xr ln 1 218for more information. 219.It "-- file unchanged" 220No savings is achieved by 221compression. The input remains virgin. 222.El 223.Sh FILES 224.Bl -tag -width file.Z 225.It Pa file.Z 226compressed file is file.Z 227.El 228.Sh BUGS 229Although compressed files are compatible between machines with large memory, 230.Fl b Ns Ar 12 231should be used for file transfer to architectures with 232a small process data space (64KB or less, as exhibited by the 233.Tn DEC PDP 234series, the Intel 80286, etc.) 235.Pp 236.Nm Compress 237should be more flexible about the existence of the `.Z' suffix. 238.Sh HISTORY 239The 240.Nm 241command appeared in 242.Bx 4.3 . 243