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