summaryrefslogtreecommitdiff
path: root/usr.bin/compress/compress.1
blob: 8d039b39c806c6d5f006b19b5922b89281008ab9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
.\"	$OpenBSD: compress.1,v 1.5 1997/08/19 06:33:37 denny Exp $
.\"	$NetBSD: compress.1,v 1.5 1995/03/26 09:44:34 glass Exp $
.\"
.\" Copyright (c) 1986, 1990, 1993
.\"	The Regents of the University of California.  All rights reserved.
.\"
.\" This code is derived from software contributed to Berkeley by
.\" James A. Woods, derived from original work by Spencer Thomas
.\" and Joseph Orost.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
.\" are met:
.\" 1. Redistributions of source code must retain the above copyright
.\"    notice, this list of conditions and the following disclaimer.
.\" 2. Redistributions in binary form must reproduce the above copyright
.\"    notice, this list of conditions and the following disclaimer in the
.\"    documentation and/or other materials provided with the distribution.
.\" 3. All advertising materials mentioning features or use of this software
.\"    must display the following acknowledgement:
.\"	This product includes software developed by the University of
.\"	California, Berkeley and its contributors.
.\" 4. Neither the name of the University nor the names of its contributors
.\"    may be used to endorse or promote products derived from this software
.\"    without specific prior written permission.
.\"
.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
.\"     @(#)compress.1	8.2 (Berkeley) 4/18/94
.\"
.Dd April 18, 1994
.Dt COMPRESS 1
.Os BSD 4.3
.Sh NAME
.Nm compress ,
.\".Nm uncompress ,
.Nm uncompress
.\".Nm zcat
.Nd compress and expand data
.Sh SYNOPSIS
.Nm compress
.Op Fl cftgOqv
.Op Fl b Ar bits
.Op Fl o Ar filename
.Op Ar
.Nm uncompress
.Op Fl cftoqv
.Op Fl o Ar filename
.Op Ar 
.\".Nm zcat
.\".Op Ar
.Sh DESCRIPTION
.Nm Compress
reduces the size of the named files using adaptive Lempel-Ziv coding.
Each
.Ar file
is renamed to the same name plus the extension
.Dq .Z .
As many of the modification time, access time, file flags, file mode,
user ID, and group ID as allowed by permissions are retained in the
new file.
If compression would not reduce the size of a
.Ar file ,
the file is ignored.
.Pp
.Nm Uncompress
restores the compressed files to their original form, renaming the
files by deleting the
.Dq .Z
extension.
.\".Pp
.\".Nm Zcat
.\"is an alias for
.\".Dq "uncompress -c" .
.Pp
If renaming the files would cause files to be overwritten and the standard
input device is a terminal, the user is prompted (on the standard error
output) for confirmation.
If prompting is not possible or confirmation is not received, the files
are not overwritten.
.Pp
If no files are specified, the standard input is compressed or uncompressed
to the standard output.
If either the input and output files are not regular files, the checks for
reduction in size and file overwriting are not performed, the input file is
not removed, and the attributes of the input file are not retained.
.Pp
The options are as follows:
.Bl -tag -width Ds
.It Fl b
Specify the
.Ar bits
code limit (see below).
.It Fl c
Compressed or uncompressed output is written to the standard output.
No files are modified.
.It Fl d
Decompress the source files instead of compressing them.
.It Fl f
Force compression of
.Ar file ,
even if it is not actually reduced in size.
Additionally, files are overwritten without prompting for confirmation.
.It Fl g
Use deflate scheme wich reported to provide better compression rates.
.It Fl O
Use old compression method (default is based on the program name).
.It Fl o
Set the output file name.
.It Fl t
Test the entefrity of each file leaving any files intact.
.It Fl q
Be quite, suppress any messages.
.It Fl v
Print the percentage reduction of each file.
.El
.Pp
.Nm Compress
uses a modified Lempel-Ziv algorithm.
Common substrings in the file are first replaced by 9-bit codes 257 and up.
When code 512 is reached, the algorithm switches to 10-bit codes and
continues to use more bits until the
limit specified by the
.Fl b
flag is reached (the default is 16).
.Ar Bits
must be between 9 and 16.
.Pp
After the
.Ar bits
limit is reached,
.Nm compress
periodically checks the compression ratio.
If it is increasing,
.Nm compress
continues to use the existing code dictionary.
However, if the compression ratio decreases,
.Nm compress
discards the table of substrings and rebuilds it from scratch.  This allows
the algorithm to adapt to the next "block" of the file.
.Pp
The
.Fl b
flag is omitted for
.Nm uncompress
since the
.Ar bits
parameter specified during compression
is encoded within the output, along with
a magic number to ensure that neither decompression of random data nor
recompression of compressed data is attempted.
.Pp
.ne 8
The amount of compression obtained depends on the size of the
input, the number of
.Ar bits
per code, and the distribution of common substrings.
Typically, text such as source code or English is reduced by 50\-60%.
Compression is generally much better than that achieved by Huffman
coding (as used in the historical command pack), or adaptive Huffman
coding (as used in the historical command compact), and takes less
time to compute.
.Pp
The
.Nm compress
utility exits 0 on success, 1 if an error occurs, and 2 if one or
more files were not compressed because they would have grown in
size (and -f was not specifed).
.Sh SEE ALSO
.Rs
.%A Welch, Terry A.
.%D June, 1984
.%T "A Technique for High Performance Data Compression"
.%J "IEEE Computer"
.%V 17:6
.%P pp. 8-19
.Re
.Sh STANDARDS
The
.Nm compress
utility is compliant with the
.St -p1003.2-92
specification.
.Sh HISTORY
The
.Nm
command appeared in
.Bx 4.3 .
The deflate compression support added in
.Ox 2.1 .