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