1994-05-27 12:33:43 +00:00
|
|
|
.\" 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.
|
2017-02-28 23:42:47 +00:00
|
|
|
.\" 3. Neither the name of the University nor the names of its contributors
|
1994-05-27 12:33:43 +00:00
|
|
|
.\" 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
|
1999-08-28 01:08:13 +00:00
|
|
|
.\" $FreeBSD$
|
1994-05-27 12:33:43 +00:00
|
|
|
.\"
|
2020-10-20 13:05:25 +00:00
|
|
|
.Dd October 20, 2020
|
1994-05-27 12:33:43 +00:00
|
|
|
.Dt COMPRESS 1
|
2001-07-10 14:16:33 +00:00
|
|
|
.Os
|
1994-05-27 12:33:43 +00:00
|
|
|
.Sh NAME
|
|
|
|
.Nm compress ,
|
2004-07-05 17:12:53 +00:00
|
|
|
.Nm uncompress
|
1994-05-27 12:33:43 +00:00
|
|
|
.Nd compress and expand data
|
|
|
|
.Sh SYNOPSIS
|
2000-11-20 19:21:22 +00:00
|
|
|
.Nm
|
2005-09-07 18:40:09 +00:00
|
|
|
.Op Fl fv
|
1994-05-27 12:33:43 +00:00
|
|
|
.Op Fl b Ar bits
|
|
|
|
.Op Ar
|
2005-09-07 18:40:09 +00:00
|
|
|
.Nm
|
|
|
|
.Fl c
|
|
|
|
.Op Fl b Ar bits
|
|
|
|
.Op Ar file
|
1994-05-27 12:33:43 +00:00
|
|
|
.Nm uncompress
|
2005-09-07 18:40:09 +00:00
|
|
|
.Op Fl f
|
2001-07-15 08:06:20 +00:00
|
|
|
.Op Ar
|
2005-09-07 18:40:09 +00:00
|
|
|
.Nm uncompress
|
|
|
|
.Fl c
|
|
|
|
.Op Ar file
|
1994-05-27 12:33:43 +00:00
|
|
|
.Sh DESCRIPTION
|
2002-04-19 23:44:58 +00:00
|
|
|
The
|
|
|
|
.Nm
|
2005-09-07 18:40:09 +00:00
|
|
|
utility reduces the size of files using adaptive Lempel-Ziv coding.
|
1994-05-27 12:33:43 +00:00
|
|
|
Each
|
|
|
|
.Ar file
|
|
|
|
is renamed to the same name plus the extension
|
2005-11-18 10:36:29 +00:00
|
|
|
.Pa .Z .
|
2005-09-07 18:40:09 +00:00
|
|
|
A
|
|
|
|
.Ar file
|
|
|
|
argument with a
|
2005-11-18 10:36:29 +00:00
|
|
|
.Pa .Z
|
2005-09-07 18:40:09 +00:00
|
|
|
extension will be ignored except it will cause an
|
|
|
|
error exit after other arguments are processed.
|
1994-05-27 12:33:43 +00:00
|
|
|
If compression would not reduce the size of a
|
|
|
|
.Ar file ,
|
|
|
|
the file is ignored.
|
|
|
|
.Pp
|
2002-04-19 23:44:58 +00:00
|
|
|
The
|
|
|
|
.Nm uncompress
|
2005-09-07 18:40:09 +00:00
|
|
|
utility restores compressed files to their original form, renaming the
|
1994-05-27 12:33:43 +00:00
|
|
|
files by deleting the
|
2005-11-18 10:36:29 +00:00
|
|
|
.Pa .Z
|
2005-09-07 18:40:09 +00:00
|
|
|
extensions.
|
|
|
|
A file specification need not include the file's
|
2005-11-18 10:36:29 +00:00
|
|
|
.Pa .Z
|
1994-05-27 12:33:43 +00:00
|
|
|
extension.
|
2005-09-07 18:40:09 +00:00
|
|
|
If a file's name in its file system does not have a
|
2005-11-18 10:36:29 +00:00
|
|
|
.Pa .Z
|
2005-09-07 18:40:09 +00:00
|
|
|
extension, it will not be uncompressed and it will cause
|
|
|
|
an error exit after other arguments are processed.
|
1994-05-27 12:33:43 +00:00
|
|
|
.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
|
2005-09-07 18:40:09 +00:00
|
|
|
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.
|
|
|
|
.Pp
|
2002-05-17 01:42:43 +00:00
|
|
|
If no files are specified or a
|
|
|
|
.Ar file
|
|
|
|
argument is a single dash
|
2002-05-29 18:12:21 +00:00
|
|
|
.Pq Sq Fl ,
|
2002-05-17 01:42:43 +00:00
|
|
|
the standard input is compressed or uncompressed to the standard output.
|
1994-05-27 12:33:43 +00:00
|
|
|
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
|
2005-09-07 18:40:09 +00:00
|
|
|
not removed, and the attributes of the input file are not retained
|
|
|
|
in the output file.
|
1994-05-27 12:33:43 +00:00
|
|
|
.Pp
|
|
|
|
The options are as follows:
|
2005-09-07 18:40:09 +00:00
|
|
|
.Bl -tag -width ".Fl b Ar bits"
|
|
|
|
.It Fl b Ar bits
|
|
|
|
The code size (see below) is limited to
|
|
|
|
.Ar bits ,
|
|
|
|
which must be in the range 9..16.
|
|
|
|
The default is 16.
|
1994-05-27 12:33:43 +00:00
|
|
|
.It Fl c
|
|
|
|
Compressed or uncompressed output is written to the standard output.
|
|
|
|
No files are modified.
|
2005-09-07 18:40:09 +00:00
|
|
|
The
|
|
|
|
.Fl v
|
|
|
|
option is ignored.
|
|
|
|
Compression is attempted even if the results will be larger than the
|
|
|
|
original.
|
1994-05-27 12:33:43 +00:00
|
|
|
.It Fl f
|
2005-09-07 18:40:09 +00:00
|
|
|
Files are overwritten without prompting for confirmation.
|
|
|
|
Also, for
|
|
|
|
.Nm compress ,
|
|
|
|
files are compressed even if they are not actually reduced in size.
|
1994-05-27 12:33:43 +00:00
|
|
|
.It Fl v
|
|
|
|
Print the percentage reduction of each file.
|
2005-09-07 18:40:09 +00:00
|
|
|
Ignored by
|
|
|
|
.Nm uncompress
|
|
|
|
or if the
|
|
|
|
.Fl c
|
|
|
|
option is also used.
|
1994-05-27 12:33:43 +00:00
|
|
|
.El
|
|
|
|
.Pp
|
2002-04-19 23:44:58 +00:00
|
|
|
The
|
|
|
|
.Nm
|
|
|
|
utility uses a modified Lempel-Ziv algorithm.
|
1994-05-27 12:33:43 +00:00
|
|
|
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
|
2005-09-07 18:40:09 +00:00
|
|
|
option or its default is reached.
|
1994-05-27 12:33:43 +00:00
|
|
|
.Pp
|
2005-09-07 18:40:09 +00:00
|
|
|
After the limit is reached,
|
2000-03-26 15:10:37 +00:00
|
|
|
.Nm
|
1994-05-27 12:33:43 +00:00
|
|
|
periodically checks the compression ratio.
|
|
|
|
If it is increasing,
|
2000-03-26 15:10:37 +00:00
|
|
|
.Nm
|
1994-05-27 12:33:43 +00:00
|
|
|
continues to use the existing code dictionary.
|
|
|
|
However, if the compression ratio decreases,
|
2000-03-26 15:10:37 +00:00
|
|
|
.Nm
|
2004-07-02 22:22:35 +00:00
|
|
|
discards the table of substrings and rebuilds it from scratch.
|
|
|
|
This allows
|
1994-05-27 12:33:43 +00:00
|
|
|
the algorithm to adapt to the next "block" of the file.
|
|
|
|
.Pp
|
|
|
|
The
|
|
|
|
.Fl b
|
2005-09-07 18:40:09 +00:00
|
|
|
option is unavailable for
|
1997-06-30 06:44:07 +00:00
|
|
|
.Nm uncompress
|
1994-05-27 12:33:43 +00:00
|
|
|
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
|
|
|
|
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.
|
2005-01-17 07:44:44 +00:00
|
|
|
.Sh EXIT STATUS
|
2002-04-09 20:40:24 +00:00
|
|
|
.Ex -std compress uncompress
|
2002-05-17 00:58:07 +00:00
|
|
|
.Pp
|
|
|
|
The
|
|
|
|
.Nm compress
|
2005-09-07 18:40:09 +00:00
|
|
|
utility exits 2 if attempting to compress a file would not reduce its size
|
2002-05-17 00:58:07 +00:00
|
|
|
and the
|
|
|
|
.Fl f
|
2005-09-07 18:40:09 +00:00
|
|
|
option was not specified and if no other error occurs.
|
2020-10-20 13:05:25 +00:00
|
|
|
.Sh EXAMPLES
|
|
|
|
Create a file
|
|
|
|
.Pa test_file
|
|
|
|
with a single line of text:
|
|
|
|
.Bd -literal -offset indent
|
|
|
|
echo "This is a test" > test_file
|
|
|
|
.Ed
|
|
|
|
.Pp
|
|
|
|
Try to reduce the size of the file using a 10-bit code and show the exit status:
|
|
|
|
.Bd -literal -offset indent
|
|
|
|
$ compress -b 10 test_file
|
|
|
|
$ echo $?
|
|
|
|
2
|
|
|
|
.Ed
|
|
|
|
.Pp
|
|
|
|
Try to compress the file and show compression percentage:
|
|
|
|
.Bd -literal -offset indent
|
|
|
|
$ compress -v test_file
|
|
|
|
test_file: file would grow; left unmodified
|
|
|
|
.Ed
|
|
|
|
.Pp
|
|
|
|
Same as above but forcing compression:
|
|
|
|
.Bd -literal -offset indent
|
|
|
|
$ compress -f -v test_file
|
|
|
|
test_file.Z: 79% expansion
|
|
|
|
.Ed
|
|
|
|
.Pp
|
|
|
|
Compress and uncompress the string
|
|
|
|
.Ql hello
|
|
|
|
on the fly:
|
|
|
|
.Bd -literal -offset indent
|
|
|
|
$ echo "hello" | compress | uncompress
|
|
|
|
hello
|
|
|
|
.Ed
|
1994-05-27 12:33:43 +00:00
|
|
|
.Sh SEE ALSO
|
2002-04-09 20:40:24 +00:00
|
|
|
.Xr gunzip 1 ,
|
|
|
|
.Xr gzexe 1 ,
|
|
|
|
.Xr gzip 1 ,
|
|
|
|
.Xr zcat 1 ,
|
|
|
|
.Xr zmore 1 ,
|
|
|
|
.Xr znew 1
|
1994-05-27 12:33:43 +00:00
|
|
|
.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
|
2002-05-17 01:54:17 +00:00
|
|
|
.Sh STANDARDS
|
|
|
|
The
|
|
|
|
.Nm compress
|
|
|
|
and
|
|
|
|
.Nm uncompress
|
|
|
|
utilities conform to
|
|
|
|
.St -p1003.1-2001 .
|
1994-05-27 12:33:43 +00:00
|
|
|
.Sh HISTORY
|
|
|
|
The
|
|
|
|
.Nm
|
|
|
|
command appeared in
|
|
|
|
.Bx 4.3 .
|
2005-09-07 18:40:09 +00:00
|
|
|
.Sh BUGS
|
|
|
|
Some of these might be considered otherwise-undocumented features.
|
|
|
|
.Pp
|
|
|
|
.Nm compress :
|
|
|
|
If the utility does not compress a file because doing so would not
|
2005-11-18 10:36:29 +00:00
|
|
|
reduce its size, and a file of the same name except with an
|
|
|
|
.Pa .Z
|
2005-09-07 18:40:09 +00:00
|
|
|
extension exists, the named file is not really ignored as stated above;
|
|
|
|
it causes a prompt to confirm the overwriting of the file with the extension.
|
|
|
|
If the operation is confirmed, that file is deleted.
|
|
|
|
.Pp
|
|
|
|
.Nm uncompress :
|
|
|
|
If an empty file is compressed (using
|
|
|
|
.Fl f ) ,
|
|
|
|
the resulting
|
2005-11-18 10:36:29 +00:00
|
|
|
.Pa .Z
|
2005-09-07 18:40:09 +00:00
|
|
|
file is also empty.
|
|
|
|
That seems right, but if
|
|
|
|
.Nm uncompress
|
|
|
|
is then used on that file, an error will occur.
|
|
|
|
.Pp
|
|
|
|
Both utilities: If a
|
|
|
|
.Sq Fl
|
|
|
|
argument is used and the utility prompts the user, the standard input
|
|
|
|
is taken as the user's reply to the prompt.
|
|
|
|
.Pp
|
|
|
|
Both utilities:
|
|
|
|
If the specified file does not exist, but a similarly-named one with (for
|
|
|
|
.Nm compress )
|
|
|
|
or without (for
|
|
|
|
.Nm uncompress )
|
|
|
|
a
|
2005-11-18 10:36:29 +00:00
|
|
|
.Pa .Z
|
2005-09-07 18:40:09 +00:00
|
|
|
extension does exist, the utility will waste the user's time by not
|
|
|
|
immediately emitting an error message about the missing file and
|
|
|
|
continuing.
|
|
|
|
Instead, it first asks for confirmation to overwrite
|
2005-11-18 10:36:29 +00:00
|
|
|
the existing file and then does not overwrite it.
|