Initial import from FreeBSD RELENG_4:
[games.git] / usr.bin / compress / compress.1
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.
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  8.2 (Berkeley) 4/18/94
37 .\" $FreeBSD: src/usr.bin/compress/compress.1,v 1.4.2.8 2002/07/15 04:41:52 keramida Exp $
38 .\"
39 .Dd May 17, 2002
40 .Dt COMPRESS 1
41 .Os
42 .Sh NAME
43 .Nm compress ,
44 .Nm uncompress ,
45 .Nd compress and expand data
46 .Sh SYNOPSIS
47 .Nm
48 .Op Fl cfv
49 .Op Fl b Ar bits
50 .Op Ar
51 .Nm uncompress
52 .Op Fl cfv
53 .Op Ar
54 .Sh DESCRIPTION
55 The
56 .Nm
57 utility reduces the size of the named files using adaptive Lempel-Ziv coding.
58 Each
59 .Ar file
60 is renamed to the same name plus the extension
61 .Dq .Z .
62 As many of the modification time, access time, file flags, file mode,
63 user ID, and group ID as allowed by permissions are retained in the
64 new file.
65 If compression would not reduce the size of a
66 .Ar file ,
67 the file is ignored.
68 .Pp
69 The
70 .Nm uncompress
71 utility restores the compressed files to their original form, renaming the
72 files by deleting the
73 .Dq .Z
74 extension.
75 .Pp
76 If renaming the files would cause files to be overwritten and the standard
77 input device is a terminal, the user is prompted (on the standard error
78 output) for confirmation.
79 If prompting is not possible or confirmation is not received, the files
80 are not overwritten.
81 .Pp
82 If no files are specified or a
83 .Ar file
84 argument is a single dash
85 .Pq Sq Fl ,
86 the standard input is compressed or uncompressed to the standard output.
87 If either the input and output files are not regular files, the checks for
88 reduction in size and file overwriting are not performed, the input file is
89 not removed, and the attributes of the input file are not retained.
90 .Pp
91 The options are as follows:
92 .Bl -tag -width indent
93 .It Fl b
94 Specify the
95 .Ar bits
96 code limit (see below).
97 .It Fl c
98 Compressed or uncompressed output is written to the standard output.
99 No files are modified.
100 .It Fl f
101 Force compression of
102 .Ar file ,
103 even if it is not actually reduced in size.
104 Additionally, files are overwritten without prompting for confirmation.
105 .It Fl v
106 Print the percentage reduction of each file.
107 .El
108 .Pp
109 The
110 .Nm
111 utility uses a modified Lempel-Ziv algorithm.
112 Common substrings in the file are first replaced by 9-bit codes 257 and up.
113 When code 512 is reached, the algorithm switches to 10-bit codes and
114 continues to use more bits until the
115 limit specified by the
116 .Fl b
117 flag is reached (the default is 16).
118 .Ar Bits
119 must be between 9 and 16.
120 .Pp
121 After the
122 .Ar bits
123 limit is reached,
124 .Nm
125 periodically checks the compression ratio.
126 If it is increasing,
127 .Nm
128 continues to use the existing code dictionary.
129 However, if the compression ratio decreases,
130 .Nm
131 discards the table of substrings and rebuilds it from scratch.  This allows
132 the algorithm to adapt to the next "block" of the file.
133 .Pp
134 The
135 .Fl b
136 flag is omitted for
137 .Nm uncompress
138 since the
139 .Ar bits
140 parameter specified during compression
141 is encoded within the output, along with
142 a magic number to ensure that neither decompression of random data nor
143 recompression of compressed data is attempted.
144 .Pp
145 The amount of compression obtained depends on the size of the
146 input, the number of
147 .Ar bits
148 per code, and the distribution of common substrings.
149 Typically, text such as source code or English is reduced by 50\-60%.
150 Compression is generally much better than that achieved by Huffman
151 coding (as used in the historical command pack), or adaptive Huffman
152 coding (as used in the historical command compact), and takes less
153 time to compute.
154 .Sh DIAGNOSTICS
155 .Ex -std compress uncompress
156 .Pp
157 The
158 .Nm compress
159 utility exits 2 if attempting to compress the file would not reduce its size
160 and the
161 .Fl f
162 option was not specified.
163 .Sh SEE ALSO
164 .Xr gunzip 1 ,
165 .Xr gzexe 1 ,
166 .Xr gzip 1 ,
167 .Xr zcat 1 ,
168 .Xr zmore 1 ,
169 .Xr znew 1
170 .Rs
171 .%A Welch, Terry A.
172 .%D June, 1984
173 .%T "A Technique for High Performance Data Compression"
174 .%J "IEEE Computer"
175 .%V 17:6
176 .%P pp. 8-19
177 .Re
178 .Sh STANDARDS
179 The
180 .Nm compress
181 and
182 .Nm uncompress
183 utilities conform to
184 .St -p1003.1-2001 .
185 .Sh HISTORY
186 The
187 .Nm
188 command appeared in
189 .Bx 4.3 .