xref: /original-bsd/usr.bin/compress/compress.1 (revision 68549010)
1.\" Copyright (c) 1986, 1990 The Regents of the University of California.
2.\" 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.\" %sccs.include.redist.man%
9.\"
10.\"     @(#)compress.1	6.10 (Berkeley) 07/30/91
11.\"
12.Dd
13.Dt COMPRESS 1
14.Os BSD 4.3
15.Sh NAME
16.Nm compress ,
17.Nm uncompress ,
18.Nm zcat
19.Nd compress and expand data
20.Sh SYNOPSIS
21.Nm compress
22.Op Fl f
23.Op Fl v
24.Op Fl c
25.Op Fl b Ar bits
26.Op Ar
27.Nm uncompress
28.Op Fl f
29.Op Fl v
30.Op Fl c
31.Ar
32.Nm zcat
33.Op Ar
34.Sh DESCRIPTION
35.Nm Compress
36reduces the size of the named files using adaptive Lempel-Ziv coding.
37Whenever possible,
38each
39.Ar file
40is replaced by one with the extension
41.Ar \&.Z ,
42while keeping the same ownership modes, access and modification times.
43If no files are specified, the standard input is compressed to the
44standard output.
45Compressed files can be restored to their original form using
46.Nm uncompress
47or
48.Nm zcat
49.Bl -tag -width Ds
50.It Fl f
51Force compression of
52.Ar file ,
53even if it does not actually shrink
54or the corresponding
55.Ar file.Z
56file already exists.
57Except when run in the background under
58.Pa /bin/sh ,
59if
60.Fl f
61is not given the user is prompted as to whether an existing
62.Ar file.Z
63file should be overwritten.
64.It Fl c
65(``cat'').
66.Nm Compress/uncompress
67writes to the standard output; no files are changed.
68The nondestructive behavior of
69.Nm zcat
70is identical to that of
71.Nm uncompress
72.Fl c .
73.It Fl b
74Specify
75.Ar bits
76code limit (see below).
77.It Fl v
78Print the percentage reduction of each file.
79.El
80.Pp
81.Nm Compress
82uses the modified Lempel-Ziv algorithm popularized in
83"A Technique for High Performance Data Compression",
84Terry A. Welch,
85.Em IEEE Computer ,
86vol. 17,
87.no 6
88(June 1984), pp. 8-19.
89Common substrings in the file are first replaced by 9-bit codes 257 and up.
90When code 512 is reached, the algorithm switches to 10-bit codes and
91continues to use more bits until the
92limit specified by the
93.Fl b
94flag is reached (default 16).
95.Ar Bits
96must be between 9 and 16.  The default can be changed in the source to allow
97.Nm compress
98to be run on a smaller machine.
99.Pp
100After the
101.Ar bits
102limit is attained,
103.Nm compress
104periodically checks the compression ratio.  If it is increasing,
105.Nm compress
106continues to use the existing code dictionary.  However,
107if the compression ratio decreases,
108.Nm compress
109discards the table of substrings and rebuilds it from scratch.  This allows
110the algorithm to adapt to the next "block" of the file.
111.Pp
112Note that the
113.Fl b
114flag is omitted for
115.Ar uncompress
116since the
117.Ar bits
118parameter specified during compression
119is encoded within the output, along with
120a magic number to ensure that neither decompression of random data nor
121recompression of compressed data is attempted.
122.Pp
123.ne 8
124The amount of compression obtained depends on the size of the
125input, the number of
126.Ar bits
127per code, and the distribution of common substrings.
128Typically, text such as source code or English
129is reduced by 50\-60%.
130Compression is generally much better than that achieved by
131Huffman coding (as used in the historical command
132pack),
133or adaptive Huffman coding (as
134used in the historical command
135compact),
136and takes less time to compute.
137.Pp
138If an error occurs, exit status is 1;
139if the last file was not compressed because it became larger, the status
140is 2; otherwise the status is 0.
141.Sh DIAGNOSTICS
142.Bl -tag -width flag
143.It "Usage: compress [-fvc] [-b maxbits] [file ...]"
144Invalid options were specified on the command line.
145.It "Missing maxbits"
146Maxbits must follow
147.Fl b .
148.It Ar file : No "not in compressed format"
149The file specified to
150.Ar uncompress
151has not been compressed.
152.It Xo
153.Ar file : No "compressed with"
154.Ar \&xx No "bits, can only handle"
155.Ar \&yy No bits
156.Xc
157.Ar File
158was compressed by a program that could deal with
159more
160.Ar bits
161than the compress code on this machine.
162Recompress the file with smaller
163.Ar bits .
164.It Ar file : No "already has .Z suffix -- no change"
165The file is assumed to be already compressed.
166Rename the file and try again.
167.It Ar file : No "filename too long to tack on .Z"
168The file cannot be compressed because its name is longer than
16912 characters.
170Rename and try again.
171This message does not occur on
172.Bx
173systems.
174.It Ar file No "already exists; do you wish to overwrite (y or n)?"
175Respond "y" if you want the output file to be replaced; "n" if not.
176.It "uncompress: corrupt input"
177A
178.Dv SIGSEGV
179violation was detected which usually means that the input file is
180corrupted.
181.It Compression: Em "xx.xx%"
182Percentage of the input saved by compression.
183(Relevant only for
184.Fl v . )
185.It "-- not a regular file: unchanged"
186When the input file is not a regular file,
187(e.g. a directory), it is
188left unaltered.
189.It "-- has" Ar xx No "other links: unchanged"
190The input file has links; it is left unchanged.  See
191.Xr ln 1
192for more information.
193.It "-- file unchanged"
194No savings is achieved by
195compression.  The input remains virgin.
196.El
197.Sh FILES
198.Bl -tag -width file.Z
199.It Pa file.Z
200compressed file is file.Z
201.El
202.Sh BUGS
203Although compressed files are compatible between machines with large memory,
204.Fl b Ns Ar 12
205should be used for file transfer to architectures with
206a small process data space (64KB or less, as exhibited by the
207.Tn DEC PDP
208series, the Intel 80286, etc.)
209.Pp
210.Nm Compress
211should be more flexible about the existence of the `.Z' suffix.
212.Sh HISTORY
213The
214.Nm
215command appeared in
216.Bx 4.3 .
217