]>
Commit | Line | Data |
---|---|---|
44a7a5ab A |
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 | .\" 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. | |
44a7a5ab A |
16 | .\" 4. Neither the name of the University nor the names of its contributors |
17 | .\" may be used to endorse or promote products derived from this software | |
18 | .\" without specific prior written permission. | |
19 | .\" | |
20 | .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND | |
21 | .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
22 | .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
23 | .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | |
24 | .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
25 | .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |
26 | .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
27 | .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
28 | .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |
29 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
30 | .\" SUCH DAMAGE. | |
31 | .\" | |
32 | .\" @(#)compress.1 8.2 (Berkeley) 4/18/94 | |
e19e38b2 | 33 | .\" $FreeBSD: src/usr.bin/compress/compress.1,v 1.23 2010/12/11 08:32:16 joel Exp $ |
44a7a5ab | 34 | .\" |
c59d3020 | 35 | .Dd May 17, 2002 |
44a7a5ab | 36 | .Dt COMPRESS 1 |
c59d3020 | 37 | .Os |
44a7a5ab A |
38 | .Sh NAME |
39 | .Nm compress , | |
44a7a5ab | 40 | .Nm uncompress |
44a7a5ab A |
41 | .Nd compress and expand data |
42 | .Sh SYNOPSIS | |
43 | .Nm | |
e19e38b2 | 44 | .Op Fl fv |
44a7a5ab A |
45 | .Op Fl b Ar bits |
46 | .Op Ar | |
e19e38b2 A |
47 | .Nm |
48 | .Fl c | |
49 | .Op Fl b Ar bits | |
74e6a095 | 50 | .Op Ar |
44a7a5ab | 51 | .Nm uncompress |
e19e38b2 | 52 | .Op Fl fv |
c59d3020 | 53 | .Op Ar |
e19e38b2 A |
54 | .Nm uncompress |
55 | .Fl c | |
74e6a095 | 56 | .Op Ar |
44a7a5ab | 57 | .Sh DESCRIPTION |
c59d3020 | 58 | The |
44a7a5ab | 59 | .Nm |
e19e38b2 | 60 | utility reduces the size of files using adaptive Lempel-Ziv coding. |
44a7a5ab A |
61 | Each |
62 | .Ar file | |
63 | is renamed to the same name plus the extension | |
e19e38b2 A |
64 | .Pa .Z . |
65 | A | |
66 | .Ar file | |
67 | argument with a | |
68 | .Pa .Z | |
69 | extension will be ignored except it will cause an | |
70 | error exit after other arguments are processed. | |
44a7a5ab A |
71 | If compression would not reduce the size of a |
72 | .Ar file , | |
73 | the file is ignored. | |
74 | .Pp | |
c59d3020 | 75 | The |
44a7a5ab | 76 | .Nm uncompress |
e19e38b2 | 77 | utility restores compressed files to their original form, renaming the |
44a7a5ab | 78 | files by deleting the |
e19e38b2 A |
79 | .Pa .Z |
80 | extensions. | |
81 | A file specification need not include the file's | |
82 | .Pa .Z | |
44a7a5ab | 83 | extension. |
e19e38b2 A |
84 | If a file's name in its file system does not have a |
85 | .Pa .Z | |
86 | extension, it will not be uncompressed and it will cause | |
87 | an error exit after other arguments are processed. | |
44a7a5ab A |
88 | .Pp |
89 | If renaming the files would cause files to be overwritten and the standard | |
90 | input device is a terminal, the user is prompted (on the standard error | |
91 | output) for confirmation. | |
92 | If prompting is not possible or confirmation is not received, the files | |
93 | are not overwritten. | |
94 | .Pp | |
e19e38b2 A |
95 | As many of the modification time, access time, file flags, file mode, |
96 | user ID, and group ID as allowed by permissions are retained in the | |
97 | new file. | |
98 | .Pp | |
c59d3020 A |
99 | If no files are specified or a |
100 | .Ar file | |
101 | argument is a single dash | |
102 | .Pq Sq Fl , | |
103 | the standard input is compressed or uncompressed to the standard output. | |
44a7a5ab A |
104 | If either the input and output files are not regular files, the checks for |
105 | reduction in size and file overwriting are not performed, the input file is | |
e19e38b2 A |
106 | not removed, and the attributes of the input file are not retained |
107 | in the output file. | |
44a7a5ab A |
108 | .Pp |
109 | The options are as follows: | |
e19e38b2 A |
110 | .Bl -tag -width ".Fl b Ar bits" |
111 | .It Fl b Ar bits | |
112 | The code size (see below) is limited to | |
113 | .Ar bits , | |
114 | which must be in the range 9..16. | |
115 | The default is 16. | |
44a7a5ab A |
116 | .It Fl c |
117 | Compressed or uncompressed output is written to the standard output. | |
118 | No files are modified. | |
e19e38b2 A |
119 | The |
120 | .Fl v | |
121 | option is ignored. | |
122 | Compression is attempted even if the results will be larger than the | |
123 | original. | |
44a7a5ab | 124 | .It Fl f |
e19e38b2 A |
125 | Files are overwritten without prompting for confirmation. |
126 | Also, for | |
127 | .Nm compress , | |
128 | files are compressed even if they are not actually reduced in size. | |
44a7a5ab A |
129 | .It Fl v |
130 | Print the percentage reduction of each file. | |
e19e38b2 A |
131 | Ignored by |
132 | .Nm uncompress | |
133 | or if the | |
134 | .Fl c | |
135 | option is also used. | |
44a7a5ab A |
136 | .El |
137 | .Pp | |
c59d3020 | 138 | The |
44a7a5ab | 139 | .Nm |
c59d3020 | 140 | utility uses a modified Lempel-Ziv algorithm. |
44a7a5ab A |
141 | Common substrings in the file are first replaced by 9-bit codes 257 and up. |
142 | When code 512 is reached, the algorithm switches to 10-bit codes and | |
143 | continues to use more bits until the | |
144 | limit specified by the | |
145 | .Fl b | |
e19e38b2 | 146 | option or its default is reached. |
44a7a5ab | 147 | .Pp |
e19e38b2 | 148 | After the limit is reached, |
44a7a5ab A |
149 | .Nm |
150 | periodically checks the compression ratio. | |
151 | If it is increasing, | |
152 | .Nm | |
153 | continues to use the existing code dictionary. | |
154 | However, if the compression ratio decreases, | |
155 | .Nm | |
c59d3020 A |
156 | discards the table of substrings and rebuilds it from scratch. |
157 | This allows | |
44a7a5ab A |
158 | the algorithm to adapt to the next "block" of the file. |
159 | .Pp | |
160 | The | |
161 | .Fl b | |
e19e38b2 | 162 | option is unavailable for |
c59d3020 | 163 | .Nm uncompress |
44a7a5ab A |
164 | since the |
165 | .Ar bits | |
166 | parameter specified during compression | |
167 | is encoded within the output, along with | |
168 | a magic number to ensure that neither decompression of random data nor | |
169 | recompression of compressed data is attempted. | |
170 | .Pp | |
44a7a5ab A |
171 | The amount of compression obtained depends on the size of the |
172 | input, the number of | |
173 | .Ar bits | |
174 | per code, and the distribution of common substrings. | |
175 | Typically, text such as source code or English is reduced by 50\-60%. | |
176 | Compression is generally much better than that achieved by Huffman | |
177 | coding (as used in the historical command pack), or adaptive Huffman | |
178 | coding (as used in the historical command compact), and takes less | |
179 | time to compute. | |
e19e38b2 | 180 | .Sh EXIT STATUS |
c59d3020 | 181 | .Ex -std compress uncompress |
44a7a5ab A |
182 | .Pp |
183 | The | |
c59d3020 | 184 | .Nm compress |
e19e38b2 | 185 | utility exits 2 if attempting to compress a file would not reduce its size |
c59d3020 A |
186 | and the |
187 | .Fl f | |
e19e38b2 | 188 | option was not specified and if no other error occurs. |
44a7a5ab | 189 | .Sh SEE ALSO |
c59d3020 A |
190 | .Xr gunzip 1 , |
191 | .Xr gzexe 1 , | |
192 | .Xr gzip 1 , | |
193 | .Xr zcat 1 , | |
194 | .Xr zmore 1 , | |
195 | .Xr znew 1 | |
44a7a5ab A |
196 | .Rs |
197 | .%A Welch, Terry A. | |
198 | .%D June, 1984 | |
199 | .%T "A Technique for High Performance Data Compression" | |
200 | .%J "IEEE Computer" | |
201 | .%V 17:6 | |
202 | .%P pp. 8-19 | |
203 | .Re | |
c59d3020 A |
204 | .Sh STANDARDS |
205 | The | |
206 | .Nm compress | |
207 | and | |
208 | .Nm uncompress | |
209 | utilities conform to | |
210 | .St -p1003.1-2001 . | |
44a7a5ab A |
211 | .Sh HISTORY |
212 | The | |
213 | .Nm | |
214 | command appeared in | |
215 | .Bx 4.3 . | |
e19e38b2 A |
216 | .Sh BUGS |
217 | Some of these might be considered otherwise-undocumented features. | |
218 | .Pp | |
219 | .Nm compress : | |
220 | If the utility does not compress a file because doing so would not | |
221 | reduce its size, and a file of the same name except with an | |
222 | .Pa .Z | |
223 | extension exists, the named file is not really ignored as stated above; | |
224 | it causes a prompt to confirm the overwriting of the file with the extension. | |
225 | If the operation is confirmed, that file is deleted. | |
226 | .Pp | |
227 | .Nm uncompress : | |
228 | If an empty file is compressed (using | |
229 | .Fl f ) , | |
230 | the resulting | |
231 | .Pa .Z | |
232 | file is also empty. | |
233 | That seems right, but if | |
234 | .Nm uncompress | |
235 | is then used on that file, an error will occur. | |
236 | .Pp | |
237 | Both utilities: If a | |
238 | .Sq Fl | |
239 | argument is used and the utility prompts the user, the standard input | |
240 | is taken as the user's reply to the prompt. | |
241 | .Pp | |
242 | Both utilities: | |
243 | If the specified file does not exist, but a similarly-named one with (for | |
244 | .Nm compress ) | |
245 | or without (for | |
246 | .Nm uncompress ) | |
247 | a | |
248 | .Pa .Z | |
249 | extension does exist, the utility will waste the user's time by not | |
250 | immediately emitting an error message about the missing file and | |
251 | continuing. | |
252 | Instead, it first asks for confirmation to overwrite | |
253 | the existing file and then does not overwrite it. |