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