1 .\" Copyright (c) 1986, 1990, 1993
2 .\" The Regents of the University of California. All rights reserved.
4 .\" This code is derived from software contributed to Berkeley by
5 .\" James A. Woods, derived from original work by Spencer Thomas
8 .\" Redistribution and use in source and binary forms, with or without
9 .\" modification, are permitted provided that the following conditions
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. 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.
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
32 .\" @(#)compress.1 8.2 (Berkeley) 4/18/94
40 .Nd compress and expand data
59 utility reduces the size of files using adaptive Lempel-Ziv coding.
62 is renamed to the same name plus the extension
68 extension will be ignored except it will cause an
69 error exit after other arguments are processed.
70 If compression would not reduce the size of a
76 utility restores compressed files to their original form, renaming the
80 A file specification need not include the file's
83 If a file's name in its file system does not have a
85 extension, it will not be uncompressed and it will cause
86 an error exit after other arguments are processed.
88 If renaming the files would cause files to be overwritten and the standard
89 input device is a terminal, the user is prompted (on the standard error
90 output) for confirmation.
91 If prompting is not possible or confirmation is not received, the files
94 As many of the modification time, access time, file flags, file mode,
95 user ID, and group ID as allowed by permissions are retained in the
98 If no files are specified or a
100 argument is a single dash
102 the standard input is compressed or uncompressed to the standard output.
103 If either the input and output files are not regular files, the checks for
104 reduction in size and file overwriting are not performed, the input file is
105 not removed, and the attributes of the input file are not retained
108 The options are as follows:
109 .Bl -tag -width ".Fl b Ar bits"
111 The code size (see below) is limited to
113 which must be in the range 9..16.
116 Compressed or uncompressed output is written to the standard output.
117 No files are modified.
121 Compression is attempted even if the results will be larger than the
124 Files are overwritten without prompting for confirmation.
127 files are compressed even if they are not actually reduced in size.
129 Print the percentage reduction of each file.
139 utility uses a modified Lempel-Ziv algorithm.
140 Common substrings in the file are first replaced by 9-bit codes 257 and up.
141 When code 512 is reached, the algorithm switches to 10-bit codes and
142 continues to use more bits until the
143 limit specified by the
145 option or its default is reached.
147 After the limit is reached,
149 periodically checks the compression ratio.
152 continues to use the existing code dictionary.
153 However, if the compression ratio decreases,
155 discards the table of substrings and rebuilds it from scratch.
157 the algorithm to adapt to the next "block" of the file.
161 option is unavailable for
165 parameter specified during compression
166 is encoded within the output, along with
167 a magic number to ensure that neither decompression of random data nor
168 recompression of compressed data is attempted.
170 The amount of compression obtained depends on the size of the
173 per code, and the distribution of common substrings.
174 Typically, text such as source code or English is reduced by 50\-60%.
175 Compression is generally much better than that achieved by Huffman
176 coding (as used in the historical command pack), or adaptive Huffman
177 coding (as used in the historical command compact), and takes less
182 is a soft or hard link
184 will replace it with a compressed copy of the file pointed to by the link.
185 The link's target file is left uncompressed.
187 .Ex -std compress uncompress
191 utility exits 2 if attempting to compress a file would not reduce its size
194 option was not specified and if no other error occurs.
198 with a single line of text:
199 .Bd -literal -offset indent
200 echo "This is a test" > test_file
203 Try to reduce the size of the file using a 10-bit code and show the exit status:
204 .Bd -literal -offset indent
205 $ compress -b 10 test_file
210 Try to compress the file and show compression percentage:
211 .Bd -literal -offset indent
212 $ compress -v test_file
213 test_file: file would grow; left unmodified
216 Same as above but forcing compression:
217 .Bd -literal -offset indent
218 $ compress -f -v test_file
219 test_file.Z: 79% expansion
222 Compress and uncompress the string
225 .Bd -literal -offset indent
226 $ echo "hello" | compress | uncompress
239 .%T "A Technique for High Performance Data Compression"
257 The program does not handle links well and has no link-handling options.
259 Some of these might be considered otherwise-undocumented features.
262 If the utility does not compress a file because doing so would not
263 reduce its size, and a file of the same name except with an
265 extension exists, the named file is not really ignored as stated above;
266 it causes a prompt to confirm the overwriting of the file with the extension.
267 If the operation is confirmed, that file is deleted.
270 If an empty file is compressed (using
275 That seems right, but if
277 is then used on that file, an error will occur.
281 argument is used and the utility prompts the user, the standard input
282 is taken as the user's reply to the prompt.
285 If the specified file does not exist, but a similarly-named one with (for
291 extension does exist, the utility will waste the user's time by not
292 immediately emitting an error message about the missing file and
294 Instead, it first asks for confirmation to overwrite
295 the existing file and then does not overwrite it.