1.\" Copyright (c) 1986, 1990, 1993 2.\" The Regents of the University of California. 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 8.2 (Berkeley) 04/18/94 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 cfv 23.Op Fl b Ar bits 24.Op Ar 25.Nm uncompress 26.Op Fl cfv 27.Op Ar 28.Nm zcat 29.Op Ar 30.Sh DESCRIPTION 31.Nm Compress 32reduces the size of the named files using adaptive Lempel-Ziv coding. 33Each 34.Ar file 35is renamed to the same name plus the extension 36.Dq .Z . 37As many of the modification time, access time, file flags, file mode, 38user ID, and group ID as allowed by permissions are retained in the 39new file. 40If compression would not reduce the size of a 41.Ar file , 42the file is ignored. 43.Pp 44.Nm Uncompress 45restores the compressed files to their original form, renaming the 46files by deleting the 47.Dq .Z 48extension. 49.Pp 50.Nm Zcat 51is an alias for 52.Dq "uncompress -c" . 53.Pp 54If renaming the files would cause files to be overwritten and the standard 55input device is a terminal, the user is prompted (on the standard error 56output) for confirmation. 57If prompting is not possible or confirmation is not received, the files 58are not overwritten. 59.Pp 60If no files are specified, the standard input is compressed or uncompressed 61to the standard output. 62If either the input and output files are not regular files, the checks for 63reduction in size and file overwriting are not performed, the input file is 64not removed, and the attributes of the input file are not retained. 65.Pp 66The options are as follows: 67.Bl -tag -width Ds 68.It Fl b 69Specify the 70.Ar bits 71code limit (see below). 72.It Fl c 73Compressed or uncompressed output is written to the standard output. 74No files are modified. 75.It Fl f 76Force compression of 77.Ar file , 78even if it is not actually reduced in size. 79Additionally, files are overwritten without prompting for confirmation. 80.It Fl v 81Print the percentage reduction of each file. 82.El 83.Pp 84.Nm Compress 85uses a modified Lempel-Ziv algorithm. 86Common substrings in the file are first replaced by 9-bit codes 257 and up. 87When code 512 is reached, the algorithm switches to 10-bit codes and 88continues to use more bits until the 89limit specified by the 90.Fl b 91flag is reached (the default is 16). 92.Ar Bits 93must be between 9 and 16. 94.Pp 95After the 96.Ar bits 97limit is reached, 98.Nm compress 99periodically checks the compression ratio. 100If it is increasing, 101.Nm compress 102continues to use the existing code dictionary. 103However, if the compression ratio decreases, 104.Nm compress 105discards the table of substrings and rebuilds it from scratch. This allows 106the algorithm to adapt to the next "block" of the file. 107.Pp 108The 109.Fl b 110flag is omitted for 111.Ar uncompress 112since the 113.Ar bits 114parameter specified during compression 115is encoded within the output, along with 116a magic number to ensure that neither decompression of random data nor 117recompression of compressed data is attempted. 118.Pp 119.ne 8 120The amount of compression obtained depends on the size of the 121input, the number of 122.Ar bits 123per code, and the distribution of common substrings. 124Typically, text such as source code or English is reduced by 50\-60%. 125Compression is generally much better than that achieved by Huffman 126coding (as used in the historical command pack), or adaptive Huffman 127coding (as used in the historical command compact), and takes less 128time to compute. 129.Pp 130The 131.Nm compress 132utility exits 0 on success, and >0 if an error occurs. 133.Sh SEE ALSO 134.Rs 135.%A Welch, Terry A. 136.%D June, 1984 137.%T "A Technique for High Performance Data Compression" 138.%J "IEEE Computer" 139.%V 17:6 140.%P pp. 8-19 141.Re 142.Sh HISTORY 143The 144.Nm 145command appeared in 146.Bx 4.3 . 147