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.\" %sccs.include.redist.man% 9.\" 10.\" @(#)compress.1 6.8 (Berkeley) 07/24/90 11.\" 12.Dd 13.Dt COMPRESS 1 14.Os BSD 4.3 15.Sh NAME 16.Nm compress , 17.Nm uncompress , 18.Nm zcat 19.Nd compress and expand data 20.Sh SYNOPSIS 21.Nm compress 22.Op Fl f 23.Op Fl v 24.Op Fl c 25.Op Fl b Ar bits 26.Ar 27.br 28.Nm uncompress 29.Op Fl f 30.Op Fl v 31.Op Fl c 32.Ar 33.br 34.Nm zcat 35.Ar 36.Sh DESCRIPTION 37.Nm Compress 38reduces the size of the named files using adaptive Lempel-Ziv coding. 39Whenever possible, 40each 41.Ar file 42is replaced by one with the extension 43.Ar \&.Z , 44while keeping the same ownership modes, access and modification times. 45If no files are specified, the standard input is compressed to the 46standard output. 47Compressed files can be restored to their original form using 48.Nm uncompress 49or 50.Nm zcat 51.Tw Ds 52.Tp Fl f 53Force compression of 54.Ar file , 55even if it does not actually shrink 56or the corresponding 57.Ar file.Z 58file already exists. 59Except when run in the background under 60.Pa /bin/sh , 61if 62.Fl f 63is not given the user is prompted as to whether an existing 64.Ar file.Z 65file should be overwritten. 66.Pp 67.Tp Fl c 68(``cat'') makes 69.Nm compress/uncompress 70write to the standard output; no files are changed. 71The nondestructive behavior of 72.Nm zcat 73is identical to that of 74.Nm uncompress 75.Fl c. 76.Tp Fl b 77Specify 78.Ar bits 79code limit (see below). 80.Tp Fl v 81Print the percentage reduction of each file. 82.Tp 83.Pp 84.Nm Compress 85uses the modified Lempel-Ziv algorithm popularized in 86"A Technique for High Performance Data Compression", 87Terry A. Welch, 88.Em IEEE Computer , 89vol. 17, no. 6 (June 1984), pp. 8-19. 90Common substrings in the file are first replaced by 9-bit codes 257 and up. 91When code 512 is reached, the algorithm switches to 10-bit codes and 92continues to use more bits until the 93limit specified by the 94.Fl b 95flag is reached (default 16). 96.Ar Bits 97must be between 9 and 16. The default can be changed in the source to allow 98.Nm compress 99to be run on a smaller machine. 100.Pp 101After the 102.Ar bits 103limit is attained, 104.Nm compress 105periodically checks the compression ratio. If it is increasing, 106.Nm compress 107continues to use the existing code dictionary. However, 108if the compression ratio decreases, 109.Nm compress 110discards the table of substrings and rebuilds it from scratch. This allows 111the algorithm to adapt to the next "block" of the file. 112.Pp 113Note that the 114.Fl b 115flag is omitted for 116.Ar uncompress 117since the 118.Ar bits 119parameter specified during compression 120is encoded within the output, along with 121a magic number to ensure that neither decompression of random data nor 122recompression of compressed data is attempted. 123.Pp 124.ne 8 125The amount of compression obtained depends on the size of the 126input, the number of 127.Ar bits 128per code, and the distribution of common substrings. 129Typically, text such as source code or English 130is reduced by 50\-60%. 131Compression is generally much better than that achieved by 132Huffman coding (as used in 133.Xr pack ) , 134or adaptive Huffman coding (as 135used in 136.Xr compact ) , 137and takes less time to compute. 138.Pp 139If an error occurs, exit status is 1, else 140if the last file was not compressed because it became larger, the status 141is 2; else the status is 0. 142.Sh DIAGNOSTICS 143Usage: compress 144.Op Fl fvc 145.Op Fl b Ar maxbits 146.Ar 147.Dl Invalid options were specified on the command line. 148.Pp 149Missing maxbits 150.Df I 151Maxbits must follow 152.Fl b . 153.De 154.Pp 155.Ar file : 156not in compressed format 157.Df I 158The file specified to 159.Ar uncompress 160has not been compressed. 161.De 162.Pp 163.Ar file : 164compressed with 165.Ar xx 166bits, can only handle 167.Ar yy 168bits 169.Df I 170.Ar File 171was compressed by a program that could deal with 172more 173.Ar bits 174than the compress code on this machine. 175Recompress the file with smaller 176.Ar bits . 177.De 178.Pp 179.Ar file : 180already has .Z suffix -- no change 181.Df I 182The file is assumed to be already compressed. 183Rename the file and try again. 184.De 185.Pp 186.Ar file : 187filename too long to tack on .Z 188.Df I 189The file cannot be compressed because its name is longer than 19012 characters. 191Rename and try again. 192This message does not occur on BSD systems. 193.De 194.Pp 195.Ar file 196already exists; do you wish to overwrite (y or n)? 197.Df I 198Respond "y" if you want the output file to be replaced; "n" if not. 199.De 200.Pp 201uncompress: corrupt input 202.Df I 203A SIGSEGV violation was detected which usually means that the input file is 204corrupted. 205.De 206.Pp 207Compression: 208.Em xx.xx% 209.Df I 210Percentage of the input saved by compression. 211(Relevant only for 212.Fl v . ) 213.De 214.Pp 215-- not a regular file: unchanged 216.Df I 217When the input file is not a regular file, 218(e.g. a directory), it is 219left unaltered. 220.De 221.Pp 222-- has 223.Ar xx 224other links: unchanged 225.Df I 226The input file has links; it is left unchanged. See 227.Xr ln 1 228for more information. 229.De 230.Pp 231-- file unchanged 232.Df I 233No savings is achieved by 234compression. The input remains virgin. 235.De 236.Pp 237.Sh FILES 238.Tw file.Z 239.Tp Pa file.Z 240compressed file is file.Z 241.Tp 242.Sh HISTORY 243Appeared in 4.3 BSD. 244.Sh "BUGS" 245Although compressed files are compatible between machines with large memory, 246.Cx Fl b 247.Ar 12 248.Cx 249should be used for file transfer to architectures with 250a small process data space (64KB or less, as exhibited by the DEC PDP 251series, the Intel 80286, etc.) 252.Pp 253.Nm Compress 254should be more flexible about the existence of the `.Z' suffix. 255