xref: /freebsd/usr.bin/compress/compress.1 (revision fae643c5795db2d9bf031c6db8a70ba8d6978c62)
19b50d902SRodney W. Grimes.\" Copyright (c) 1986, 1990, 1993
29b50d902SRodney W. Grimes.\"	The Regents of the University of California.  All rights reserved.
39b50d902SRodney W. Grimes.\"
49b50d902SRodney W. Grimes.\" This code is derived from software contributed to Berkeley by
59b50d902SRodney W. Grimes.\" James A. Woods, derived from original work by Spencer Thomas
69b50d902SRodney W. Grimes.\" and Joseph Orost.
79b50d902SRodney W. Grimes.\"
89b50d902SRodney W. Grimes.\" Redistribution and use in source and binary forms, with or without
99b50d902SRodney W. Grimes.\" modification, are permitted provided that the following conditions
109b50d902SRodney W. Grimes.\" are met:
119b50d902SRodney W. Grimes.\" 1. Redistributions of source code must retain the above copyright
129b50d902SRodney W. Grimes.\"    notice, this list of conditions and the following disclaimer.
139b50d902SRodney W. Grimes.\" 2. Redistributions in binary form must reproduce the above copyright
149b50d902SRodney W. Grimes.\"    notice, this list of conditions and the following disclaimer in the
159b50d902SRodney W. Grimes.\"    documentation and/or other materials provided with the distribution.
169b50d902SRodney W. Grimes.\" 3. All advertising materials mentioning features or use of this software
179b50d902SRodney W. Grimes.\"    must display the following acknowledgement:
189b50d902SRodney W. Grimes.\"	This product includes software developed by the University of
199b50d902SRodney W. Grimes.\"	California, Berkeley and its contributors.
209b50d902SRodney W. Grimes.\" 4. Neither the name of the University nor the names of its contributors
219b50d902SRodney W. Grimes.\"    may be used to endorse or promote products derived from this software
229b50d902SRodney W. Grimes.\"    without specific prior written permission.
239b50d902SRodney W. Grimes.\"
249b50d902SRodney W. Grimes.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
259b50d902SRodney W. Grimes.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
269b50d902SRodney W. Grimes.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
279b50d902SRodney W. Grimes.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
289b50d902SRodney W. Grimes.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
299b50d902SRodney W. Grimes.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
309b50d902SRodney W. Grimes.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
319b50d902SRodney W. Grimes.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
329b50d902SRodney W. Grimes.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
339b50d902SRodney W. Grimes.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
349b50d902SRodney W. Grimes.\" SUCH DAMAGE.
359b50d902SRodney W. Grimes.\"
369b50d902SRodney W. Grimes.\"     @(#)compress.1	8.2 (Berkeley) 4/18/94
37c3aac50fSPeter Wemm.\" $FreeBSD$
389b50d902SRodney W. Grimes.\"
399b50d902SRodney W. Grimes.Dd April 18, 1994
409b50d902SRodney W. Grimes.Dt COMPRESS 1
419b50d902SRodney W. Grimes.Os BSD 4.3
429b50d902SRodney W. Grimes.Sh NAME
439b50d902SRodney W. Grimes.Nm compress ,
449b50d902SRodney W. Grimes.Nm uncompress ,
459b50d902SRodney W. Grimes.Nm zcat
469b50d902SRodney W. Grimes.Nd compress and expand data
479b50d902SRodney W. Grimes.Sh SYNOPSIS
489b50d902SRodney W. Grimes.Nm compress
499b50d902SRodney W. Grimes.Op Fl cfv
509b50d902SRodney W. Grimes.Op Fl b Ar bits
519b50d902SRodney W. Grimes.Op Ar
529b50d902SRodney W. Grimes.Nm uncompress
539b50d902SRodney W. Grimes.Op Fl cfv
549b50d902SRodney W. Grimes.Op Ar
559b50d902SRodney W. Grimes.Nm zcat
569b50d902SRodney W. Grimes.Op Ar
579b50d902SRodney W. Grimes.Sh DESCRIPTION
589b50d902SRodney W. Grimes.Nm Compress
599b50d902SRodney W. Grimesreduces the size of the named files using adaptive Lempel-Ziv coding.
609b50d902SRodney W. GrimesEach
619b50d902SRodney W. Grimes.Ar file
629b50d902SRodney W. Grimesis renamed to the same name plus the extension
639b50d902SRodney W. Grimes.Dq .Z .
649b50d902SRodney W. GrimesAs many of the modification time, access time, file flags, file mode,
659b50d902SRodney W. Grimesuser ID, and group ID as allowed by permissions are retained in the
669b50d902SRodney W. Grimesnew file.
679b50d902SRodney W. GrimesIf compression would not reduce the size of a
689b50d902SRodney W. Grimes.Ar file ,
699b50d902SRodney W. Grimesthe file is ignored.
709b50d902SRodney W. Grimes.Pp
719b50d902SRodney W. Grimes.Nm Uncompress
729b50d902SRodney W. Grimesrestores the compressed files to their original form, renaming the
739b50d902SRodney W. Grimesfiles by deleting the
749b50d902SRodney W. Grimes.Dq .Z
759b50d902SRodney W. Grimesextension.
769b50d902SRodney W. Grimes.Pp
779b50d902SRodney W. Grimes.Nm Zcat
789b50d902SRodney W. Grimesis an alias for
799b50d902SRodney W. Grimes.Dq "uncompress -c" .
809b50d902SRodney W. Grimes.Pp
819b50d902SRodney W. GrimesIf renaming the files would cause files to be overwritten and the standard
829b50d902SRodney W. Grimesinput device is a terminal, the user is prompted (on the standard error
839b50d902SRodney W. Grimesoutput) for confirmation.
849b50d902SRodney W. GrimesIf prompting is not possible or confirmation is not received, the files
859b50d902SRodney W. Grimesare not overwritten.
869b50d902SRodney W. Grimes.Pp
879b50d902SRodney W. GrimesIf no files are specified, the standard input is compressed or uncompressed
889b50d902SRodney W. Grimesto the standard output.
899b50d902SRodney W. GrimesIf either the input and output files are not regular files, the checks for
909b50d902SRodney W. Grimesreduction in size and file overwriting are not performed, the input file is
919b50d902SRodney W. Grimesnot removed, and the attributes of the input file are not retained.
929b50d902SRodney W. Grimes.Pp
939b50d902SRodney W. GrimesThe options are as follows:
94fae643c5SPhilippe Charnier.Bl -tag -width indent
959b50d902SRodney W. Grimes.It Fl b
969b50d902SRodney W. GrimesSpecify the
979b50d902SRodney W. Grimes.Ar bits
989b50d902SRodney W. Grimescode limit (see below).
999b50d902SRodney W. Grimes.It Fl c
1009b50d902SRodney W. GrimesCompressed or uncompressed output is written to the standard output.
1019b50d902SRodney W. GrimesNo files are modified.
1029b50d902SRodney W. Grimes.It Fl f
1039b50d902SRodney W. GrimesForce compression of
1049b50d902SRodney W. Grimes.Ar file ,
1059b50d902SRodney W. Grimeseven if it is not actually reduced in size.
1069b50d902SRodney W. GrimesAdditionally, files are overwritten without prompting for confirmation.
1079b50d902SRodney W. Grimes.It Fl v
1089b50d902SRodney W. GrimesPrint the percentage reduction of each file.
1099b50d902SRodney W. Grimes.El
1109b50d902SRodney W. Grimes.Pp
1119b50d902SRodney W. Grimes.Nm Compress
1129b50d902SRodney W. Grimesuses a modified Lempel-Ziv algorithm.
1139b50d902SRodney W. GrimesCommon substrings in the file are first replaced by 9-bit codes 257 and up.
1149b50d902SRodney W. GrimesWhen code 512 is reached, the algorithm switches to 10-bit codes and
1159b50d902SRodney W. Grimescontinues to use more bits until the
1169b50d902SRodney W. Grimeslimit specified by the
1179b50d902SRodney W. Grimes.Fl b
1189b50d902SRodney W. Grimesflag is reached (the default is 16).
1199b50d902SRodney W. Grimes.Ar Bits
1209b50d902SRodney W. Grimesmust be between 9 and 16.
1219b50d902SRodney W. Grimes.Pp
1229b50d902SRodney W. GrimesAfter the
1239b50d902SRodney W. Grimes.Ar bits
1249b50d902SRodney W. Grimeslimit is reached,
125fae643c5SPhilippe Charnier.Nm
1269b50d902SRodney W. Grimesperiodically checks the compression ratio.
1279b50d902SRodney W. GrimesIf it is increasing,
128fae643c5SPhilippe Charnier.Nm
1299b50d902SRodney W. Grimescontinues to use the existing code dictionary.
1309b50d902SRodney W. GrimesHowever, if the compression ratio decreases,
131fae643c5SPhilippe Charnier.Nm
1329b50d902SRodney W. Grimesdiscards the table of substrings and rebuilds it from scratch.  This allows
1339b50d902SRodney W. Grimesthe algorithm to adapt to the next "block" of the file.
1349b50d902SRodney W. Grimes.Pp
1359b50d902SRodney W. GrimesThe
1369b50d902SRodney W. Grimes.Fl b
1379b50d902SRodney W. Grimesflag is omitted for
13825537080SPhilippe Charnier.Nm uncompress
1399b50d902SRodney W. Grimessince the
1409b50d902SRodney W. Grimes.Ar bits
1419b50d902SRodney W. Grimesparameter specified during compression
1429b50d902SRodney W. Grimesis encoded within the output, along with
1439b50d902SRodney W. Grimesa magic number to ensure that neither decompression of random data nor
1449b50d902SRodney W. Grimesrecompression of compressed data is attempted.
1459b50d902SRodney W. Grimes.Pp
1469b50d902SRodney W. Grimes.ne 8
1479b50d902SRodney W. GrimesThe amount of compression obtained depends on the size of the
1489b50d902SRodney W. Grimesinput, the number of
1499b50d902SRodney W. Grimes.Ar bits
1509b50d902SRodney W. Grimesper code, and the distribution of common substrings.
1519b50d902SRodney W. GrimesTypically, text such as source code or English is reduced by 50\-60%.
1529b50d902SRodney W. GrimesCompression is generally much better than that achieved by Huffman
1539b50d902SRodney W. Grimescoding (as used in the historical command pack), or adaptive Huffman
1549b50d902SRodney W. Grimescoding (as used in the historical command compact), and takes less
1559b50d902SRodney W. Grimestime to compute.
156fae643c5SPhilippe Charnier.Sh DIAGNOSTICS
1579b50d902SRodney W. GrimesThe
158fae643c5SPhilippe Charnier.Nm
1599b50d902SRodney W. Grimesutility exits 0 on success, and >0 if an error occurs.
1609b50d902SRodney W. Grimes.Sh SEE ALSO
1619b50d902SRodney W. Grimes.Rs
1629b50d902SRodney W. Grimes.%A Welch, Terry A.
1639b50d902SRodney W. Grimes.%D June, 1984
1649b50d902SRodney W. Grimes.%T "A Technique for High Performance Data Compression"
1659b50d902SRodney W. Grimes.%J "IEEE Computer"
1669b50d902SRodney W. Grimes.%V 17:6
1679b50d902SRodney W. Grimes.%P pp. 8-19
1689b50d902SRodney W. Grimes.Re
1699b50d902SRodney W. Grimes.Sh HISTORY
1709b50d902SRodney W. GrimesThe
1719b50d902SRodney W. Grimes.Nm
1729b50d902SRodney W. Grimescommand appeared in
1739b50d902SRodney W. Grimes.Bx 4.3 .
174