xref: /openbsd-src/usr.bin/compress/compress.1 (revision 3ab258a16e35bc5259bb711e9cca5c9e26d26fc9)
1*3ab258a1Smillert.\"	$OpenBSD: compress.1,v 1.49 2022/10/22 14:41:27 millert Exp $
2df930be7Sderaadt.\"	$NetBSD: compress.1,v 1.5 1995/03/26 09:44:34 glass Exp $
3df930be7Sderaadt.\"
4df930be7Sderaadt.\" Copyright (c) 1986, 1990, 1993
5df930be7Sderaadt.\"	The Regents of the University of California.  All rights reserved.
6df930be7Sderaadt.\"
7df930be7Sderaadt.\" This code is derived from software contributed to Berkeley by
8df930be7Sderaadt.\" James A. Woods, derived from original work by Spencer Thomas
9df930be7Sderaadt.\" and Joseph Orost.
10df930be7Sderaadt.\"
11df930be7Sderaadt.\" Redistribution and use in source and binary forms, with or without
12df930be7Sderaadt.\" modification, are permitted provided that the following conditions
13df930be7Sderaadt.\" are met:
14df930be7Sderaadt.\" 1. Redistributions of source code must retain the above copyright
15df930be7Sderaadt.\"    notice, this list of conditions and the following disclaimer.
16df930be7Sderaadt.\" 2. Redistributions in binary form must reproduce the above copyright
17df930be7Sderaadt.\"    notice, this list of conditions and the following disclaimer in the
18df930be7Sderaadt.\"    documentation and/or other materials provided with the distribution.
19f75387cbSmillert.\" 3. Neither the name of the University nor the names of its contributors
20df930be7Sderaadt.\"    may be used to endorse or promote products derived from this software
21df930be7Sderaadt.\"    without specific prior written permission.
22df930be7Sderaadt.\"
23df930be7Sderaadt.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24df930be7Sderaadt.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25df930be7Sderaadt.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26df930be7Sderaadt.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27df930be7Sderaadt.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28df930be7Sderaadt.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29df930be7Sderaadt.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30df930be7Sderaadt.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31df930be7Sderaadt.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32df930be7Sderaadt.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33df930be7Sderaadt.\" SUCH DAMAGE.
34df930be7Sderaadt.\"
35df930be7Sderaadt.\"     @(#)compress.1	8.2 (Berkeley) 4/18/94
36df930be7Sderaadt.\"
37*3ab258a1Smillert.Dd $Mdocdate: October 22 2022 $
38df930be7Sderaadt.Dt COMPRESS 1
392e0eb34fSaaron.Os
40df930be7Sderaadt.Sh NAME
41df930be7Sderaadt.Nm compress ,
42f3e55573Sderaadt.Nm uncompress ,
433a68a017Sjmc.Nm zcat
443a68a017Sjmc.Nd compress and expand data (compress mode)
45df930be7Sderaadt.Sh SYNOPSIS
46df930be7Sderaadt.Nm compress
47a787e6e8Ssobrado.Op Fl 123456789cdfghlNnOqrtv
48df930be7Sderaadt.Op Fl b Ar bits
49f041f44aSmickey.Op Fl o Ar filename
500214b827Sjmc.Op Fl S Ar suffix
51df930be7Sderaadt.Op Ar
52df930be7Sderaadt.Nm uncompress
53a787e6e8Ssobrado.Op Fl cfhlNnqrtv
54f041f44aSmickey.Op Fl o Ar filename
55df930be7Sderaadt.Op Ar
56f29e2573Smickey.Nm zcat
5772bf57baSjmc.Op Fl fghqr
5872bf57baSjmc.Op Ar
59df930be7Sderaadt.Sh DESCRIPTION
6017c11583SaaronThe
613a68a017Sjmc.Nm
623a68a017Sjmcutility
633a68a017Sjmcreduces the size of the named files using adaptive Lempel-Ziv coding,
643a68a017Sjmcin compress mode.
6554f824e5SjmcIf invoked as
6672bf57baSjmc.Nm compress Fl g ,
673a68a017Sjmcthe deflate mode of compression is chosen;
683a68a017Sjmcsee
693a68a017Sjmc.Xr gzip 1
703a68a017Sjmcfor more information.
713a68a017SjmcEach file is renamed to the same name plus the extension
723a68a017Sjmc.Dq .Z .
73df930be7SderaadtAs many of the modification time, access time, file flags, file mode,
74df930be7Sderaadtuser ID, and group ID as allowed by permissions are retained in the
75df930be7Sderaadtnew file.
763a68a017SjmcIf compression would not reduce the size of a file,
776b0cc2f2Smickeythe file is ignored (unless
786b0cc2f2Smickey.Fl f
796b0cc2f2Smickeyis used).
80df930be7Sderaadt.Pp
8117c11583SaaronThe
82a06b6ec4Saaron.Nm uncompress
833a68a017Sjmcutility restores compressed files to their original form, renaming the
84c8d7f545Smillertfiles by removing the extension (or by using the stored name if the
85c8d7f545Smillert.Fl N
86c8d7f545Smillertflag is specified).
87*3ab258a1SmillertIt has the ability to restore files compressed by
88*3ab258a1Smillert.Nm ,
893a68a017Sjmc.Xr gzip 1 ,
90*3ab258a1Smillertand
91*3ab258a1Smillert.Xr zip 1 ,
923a68a017Sjmcrecognising the following extensions:
93c8d7f545Smillert.Dq .Z ,
94c8d7f545Smillert.Dq -Z ,
95c8d7f545Smillert.Dq _Z ,
96c8d7f545Smillert.Dq .gz ,
97c8d7f545Smillert.Dq -gz ,
98c8d7f545Smillert.Dq _gz ,
99c8d7f545Smillert.Dq .tgz ,
100c8d7f545Smillert.Dq -tgz ,
101c8d7f545Smillert.Dq _tgz ,
102c8d7f545Smillert.Dq .taz ,
103c8d7f545Smillert.Dq -taz ,
104c8d7f545Smillertand
105c8d7f545Smillert.Dq _taz .
106*3ab258a1SmillertThe
107*3ab258a1Smillert.Fl S
108*3ab258a1Smillertoption can be used to support other file extensions.
1099b8cc0e9SjmcExtensions ending in
110c8d7f545Smillert.Dq tgz
111c8d7f545Smillertand
112c8d7f545Smillert.Dq taz
113c8d7f545Smillertare not removed when decompressing, instead they are converted to
114c8d7f545Smillert.Dq tar .
115*3ab258a1SmillertFiles in zip format are only supported if they contain a single member
116*3ab258a1Smillerteither compressed with the deflate scheme or stored uncompressed.
117df930be7Sderaadt.Pp
118f29e2573SmickeyThe
119f29e2573Smickey.Nm zcat
1207b7ca460Smickeycommand is equivalent in functionality to
121f29e2573Smickey.Nm uncompress
1227b7ca460Smickey.Fl c .
123f29e2573Smickey.Pp
124df930be7SderaadtIf renaming the files would cause files to be overwritten and the standard
125df930be7Sderaadtinput device is a terminal, the user is prompted (on the standard error
126df930be7Sderaadtoutput) for confirmation.
127df930be7SderaadtIf prompting is not possible or confirmation is not received, the files
128df930be7Sderaadtare not overwritten.
129df930be7Sderaadt.Pp
130df930be7SderaadtIf no files are specified, the standard input is compressed or uncompressed
131df930be7Sderaadtto the standard output.
13217c11583SaaronIf either the input or output files are not regular files, the checks for
133df930be7Sderaadtreduction in size and file overwriting are not performed, the input file is
134df930be7Sderaadtnot removed, and the attributes of the input file are not retained.
135df930be7Sderaadt.Pp
1369f9b3673SmillertBy default, when compressing using the deflate scheme
1379f9b3673Smillert.Pf ( Fl g ) ,
138fafb0b17Sjmcthe original file name and time stamp are stored in the compressed file.
1399f9b3673SmillertWhen uncompressing, this information is not used.
1409f9b3673SmillertInstead, the uncompressed file inherits the time stamp of the
1419f9b3673Smillertcompressed version and the uncompressed file name is generated from
1429f9b3673Smillertthe name of the compressed file as described above.
1439f9b3673SmillertThese defaults may be overridden by the
1449f9b3673Smillert.Fl N
1459f9b3673Smillertand
1469f9b3673Smillert.Fl n
1479f9b3673Smillertflags, described below.
1489f9b3673Smillert.Pp
149df930be7SderaadtThe options are as follows:
150df930be7Sderaadt.Bl -tag -width Ds
1510214b827Sjmc.It Fl 1...9
1523a68a017SjmcUse the deflate scheme, with compression factor of
1530214b827Sjmc.Fl 1
1540214b827Sjmcto
1550214b827Sjmc.Fl 9 .
1560214b827SjmcCompression factor
1570214b827Sjmc.Fl 1
1580214b827Sjmcis the fastest, but provides a poorer level of compression.
1590214b827SjmcCompression factor
1600214b827Sjmc.Fl 9
1610214b827Sjmcprovides the best level of compression, but is relatively slow.
1620214b827SjmcThe default is
1630214b827Sjmc.Fl 6 .
1640214b827SjmcThis option implies
1650214b827Sjmc.Fl g .
166a06b6ec4Saaron.It Fl b Ar bits
167df930be7SderaadtSpecify the
168df930be7Sderaadt.Ar bits
1697a491e8dSjmccode limit
1707a491e8dSjmc.Pq see below .
171df930be7Sderaadt.It Fl c
172df930be7SderaadtCompressed or uncompressed output is written to the standard output.
1736b0cc2f2SmickeyNo files are modified (force
1746b0cc2f2Smickey.Nm zcat
1756b0cc2f2Smickeymode).
176f041f44aSmickey.It Fl d
1776b0cc2f2SmickeyDecompress the source files instead of compressing them (force
1786b0cc2f2Smickey.Nm uncompress
1796b0cc2f2Smickeymode).
180df930be7Sderaadt.It Fl f
181df930be7SderaadtForce compression of
182df930be7Sderaadt.Ar file ,
183df930be7Sderaadteven if it is not actually reduced in size.
184df930be7SderaadtAdditionally, files are overwritten without prompting for confirmation.
1854b1ca57aSteduIf the input data is not in a format recognized by
1864b1ca57aStedu.Nm
1874b1ca57aSteduand if the option
1884b1ca57aStedu.Fl c
1894b1ca57aSteduis also given, copy the input data without change
1906347d36eSjmcto the standard output: let
1914b1ca57aStedu.Nm zcat
1924b1ca57aStedubehave as
19372bf57baSjmc.Xr cat 1 .
194f041f44aSmickey.It Fl g
1953a68a017SjmcUse the deflate scheme, which reportedly provides better compression rates
1963a68a017Sjmc(force
1973a68a017Sjmc.Xr gzip 1
1986b0cc2f2Smickeymode).
1994211bcc1Smillert.It Fl h
2004211bcc1SmillertPrint a short help message.
201b2b9c6b0Smillert.It Fl l
202b2b9c6b0SmillertList information for the specified compressed files.
203b2b9c6b0SmillertThe following information is listed:
2047a491e8dSjmc.Bl -tag -width "compression ratio"
205b2b9c6b0Smillert.It compressed size
2067a491e8dSjmcSize of the compressed file.
207b2b9c6b0Smillert.It uncompressed size
2087a491e8dSjmcSize of the file when uncompressed.
209b2b9c6b0Smillert.It compression ratio
2107a491e8dSjmcRatio of the difference between the compressed and uncompressed
211b2b9c6b0Smillertsizes to the uncompressed size.
212b2b9c6b0Smillert.It uncompressed name
2137a491e8dSjmcName the file will be saved as when uncompressing.
214b2b9c6b0Smillert.El
215b2b9c6b0Smillert.Pp
216b2b9c6b0SmillertIf the
217b2b9c6b0Smillert.Fl v
218b2b9c6b0Smillertoption is specified, the following additional information is printed:
2197a491e8dSjmc.Bl -tag -width "compression method"
220b2b9c6b0Smillert.It compression method
2217a491e8dSjmcName of the method used to compress the file.
222b2b9c6b0Smillert.It crc
2237a491e8dSjmc32-bit CRC
2247a491e8dSjmc.Pq cyclic redundancy code
2257a491e8dSjmcof the uncompressed file.
226b2b9c6b0Smillert.It "time stamp"
2277a491e8dSjmcDate and time corresponding to the last data modification time
228b2b9c6b0Smillert(mtime) of the compressed file (if the
229b2b9c6b0Smillert.Fl n
230b2b9c6b0Smillertoption is specified, the time stamp stored in the compressed file
231b2b9c6b0Smillertis printed instead).
232b2b9c6b0Smillert.El
2330214b827Sjmc.It Fl N
2340214b827SjmcWhen uncompressing or listing, use the time stamp and file name stored
2350214b827Sjmcin the compressed file, if any, for the uncompressed version.
2369f9b3673SmillertThis information is only available when the deflate scheme
2373a68a017Sjmc.Pf ( Fl g )
2383a68a017Sjmcis used.
2399f9b3673Smillert.It Fl n
2409f9b3673SmillertWhen compressing, do not store the original file name and time stamp
2419f9b3673Smillertin the header of the compressed file.
242f041f44aSmickey.It Fl O
2433a68a017SjmcUse compress mode
2443a68a017Sjmc(the default).
245a06b6ec4Saaron.It Fl o Ar filename
246f041f44aSmickeySet the output file name.
2470214b827Sjmc.It Fl q
2483a68a017SjmcBe quiet: suppress all messages.
24977aa7570Smillert.It Fl r
2503a68a017SjmcRecursive mode:
25177aa7570Smillert.Nm
25277aa7570Smillertwill descend into specified directories.
2530214b827Sjmc.It Fl S Ar suffix
254*3ab258a1SmillertWhen compressing, use the specified
255*3ab258a1Smillert.Ar suffix
256*3ab258a1Smillertas the extension when creating output files.
257*3ab258a1SmillertWhen uncompressing, recognize file names with the specified
258*3ab258a1Smillert.Ar suffix
259*3ab258a1Smillertas compressed files.
2600214b827Sjmc.It Fl t
2610214b827SjmcTest the integrity of each file leaving any files intact.
262df930be7Sderaadt.It Fl v
2636b0cc2f2SmickeyPrint the percentage reduction of each file and other information.
264df930be7Sderaadt.El
265df930be7Sderaadt.Pp
266581190f2Saaron.Nm
26754f824e5Sjmcuses a modified Lempel-Ziv algorithm
26854f824e5Sjmc.Pq LZW .
269df930be7SderaadtCommon substrings in the file are first replaced by 9-bit codes 257 and up.
270df930be7SderaadtWhen code 512 is reached, the algorithm switches to 10-bit codes and
271df930be7Sderaadtcontinues to use more bits until the
272df930be7Sderaadtlimit specified by the
273df930be7Sderaadt.Fl b
27417c11583Saaronflag is reached.
275a06b6ec4Saaron.Ar bits
2767a491e8dSjmcmust be between 9 and 16
2777a491e8dSjmc.Pq the default is 16 .
278df930be7Sderaadt.Pp
279df930be7SderaadtAfter the
280df930be7Sderaadt.Ar bits
281df930be7Sderaadtlimit is reached,
282581190f2Saaron.Nm
283df930be7Sderaadtperiodically checks the compression ratio.
284df930be7SderaadtIf it is increasing,
285581190f2Saaron.Nm
286df930be7Sderaadtcontinues to use the existing code dictionary.
287df930be7SderaadtHowever, if the compression ratio decreases,
288581190f2Saaron.Nm
289bf9a4e5fSaarondiscards the table of substrings and rebuilds it from scratch.
290bf9a4e5fSaaronThis allows the algorithm to adapt to the next
291581190f2Saaron.Dq block
292581190f2Saaronof the file.
293df930be7Sderaadt.Pp
294df930be7SderaadtThe
295df930be7Sderaadt.Fl b
296df930be7Sderaadtflag is omitted for
297b9fb25d9Sderaadt.Nm uncompress
298df930be7Sderaadtsince the
299df930be7Sderaadt.Ar bits
300df930be7Sderaadtparameter specified during compression
301df930be7Sderaadtis encoded within the output, along with
302df930be7Sderaadta magic number to ensure that neither decompression of random data nor
303df930be7Sderaadtrecompression of compressed data is attempted.
304df930be7Sderaadt.Pp
305df930be7SderaadtThe amount of compression obtained depends on the size of the
306df930be7Sderaadtinput, the number of
307df930be7Sderaadt.Ar bits
308df930be7Sderaadtper code, and the distribution of common substrings.
30954f824e5SjmcTypically, text such as source code or English is reduced by 50 \- 60% using
3103a68a017Sjmc.Nm .
311df930be7SderaadtCompression is generally much better than that achieved by Huffman
312df930be7Sderaadtcoding (as used in the historical command pack), or adaptive Huffman
313df930be7Sderaadtcoding (as used in the historical command compact), and takes less
314df930be7Sderaadttime to compute.
315f1c64ac4Sjmc.Sh EXIT STATUS
316df930be7SderaadtThe
31711fbf7b0Sjmc.Nm compress
31811fbf7b0Sjmcutility exits with one of the following values:
31911fbf7b0Sjmc.Pp
320f1c64ac4Sjmc.Bl -tag -width Ds -offset indent -compact
32111fbf7b0Sjmc.It 0
32211fbf7b0SjmcSuccess.
32311fbf7b0Sjmc.It 1
32411fbf7b0SjmcAn error occurred.
32511fbf7b0Sjmc.It 2
32611fbf7b0SjmcAt least one of the specified files was not compressed since
32711fbf7b0Sjmc.Fl f
32811fbf7b0Sjmcwas not specified and compression would have resulted in a size
32911fbf7b0Sjmcincrease.
33011fbf7b0Sjmc.It \*(Gt2
33111fbf7b0SjmcAn error occurred.
33211fbf7b0Sjmc.El
33311fbf7b0Sjmc.Pp
33460eca5eaSjmc.Ex -std uncompress zcat
335df930be7Sderaadt.Sh SEE ALSO
336d6368665Sjmc.Xr gzexe 1 ,
3373a68a017Sjmc.Xr gzip 1 ,
338d6368665Sjmc.Xr zdiff 1 ,
339d6368665Sjmc.Xr zforce 1 ,
340d6368665Sjmc.Xr zmore 1 ,
341d6368665Sjmc.Xr znew 1 ,
3426347d36eSjmc.Xr compress 3
343df930be7Sderaadt.Rs
344df930be7Sderaadt.%A Welch, Terry A.
345df930be7Sderaadt.%D June, 1984
346df930be7Sderaadt.%T "A Technique for High Performance Data Compression"
347df930be7Sderaadt.%J "IEEE Computer"
348df930be7Sderaadt.%V 17:6
349d6368665Sjmc.%P pp. 8\-19
350df930be7Sderaadt.Re
351bd70e02dSdenny.Sh STANDARDS
352bd70e02dSdennyThe
3537c5a075bSjmc.Nm ,
3547c5a075bSjmc.Nm uncompress ,
3557c5a075bSjmcand
3567c5a075bSjmc.Nm zcat
3577c5a075bSjmcutilities are compliant with the
3583dba4d0dSjmcX/Open System Interfaces option of the
3593dba4d0dSjmc.St -p1003.1-2008
360bd70e02dSdennyspecification.
3617c5a075bSjmc.Pp
3627c5a075bSjmcThe
3637c5a075bSjmc.Nm
3647c5a075bSjmcflags
365a787e6e8Ssobrado.Op Fl 123456789dghlNnOoqrSt ,
3667c5a075bSjmc.Nm uncompress
3677c5a075bSjmcflags
368a787e6e8Ssobrado.Op Fl hlNnoqrt ,
3697c5a075bSjmcand the
3707c5a075bSjmc.Nm zcat
3717c5a075bSjmcflags
3727c5a075bSjmc.Op Fl fghqr
3737c5a075bSjmcare extensions to that specification.
3743dba4d0dSjmc.Pp
3753dba4d0dSjmc.St -p1003.1-2008
3763dba4d0dSjmcspecifies a maximum bits limit
3773dba4d0dSjmc.Pq Fl b
3783dba4d0dSjmcof 14 to
3793dba4d0dSjmc.Qq achieve portability to all systems .
380df930be7Sderaadt.Sh HISTORY
381df930be7SderaadtThe
382df930be7Sderaadt.Nm
383df930be7Sderaadtcommand appeared in
384df930be7Sderaadt.Bx 4.3 .
3853a68a017SjmcDeflate compression support was added in
386f041f44aSmickey.Ox 2.1 .
387