compress(1) compress(1)NAME compress, compressdir, uncompress, uncompressdir, zcat, zcmp, zdiff, zmore - compress files and directories as well as expand them; support concatenation, browsing, and file- comparing operations upon compressed files SYNOPSIS compress [-b maxbits] [-c] [-f] [-v] [-V] [file]... compressdir [compress-flag]... [directory]... uncompressdir [uncompress-flag]... [directory]... uncompress [-c] [-f] [-v] [-V] [file]... zcat [-V] [file]... zcmp [cmp-option]... file1 [file2] zdiff [diff-option]... file1 [file2] zmore [file]... ARGUMENTS -b maxbits Uses maxbits as the maximum number of bits to use in codes when compressing file. The compress command uses a modified Lempel-Ziv algorithm according to which 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 -b option, is reached (default 16). The maxbits specification must be between 9 and 16. (The default can be changed in the source to allow compress to be run on a smaller machine.) After the maxbits limit is attained, compress periodically checks the compression ratio. If it is increasing, compress continues to use the existing code dictionary. However, if the compression ratio decreases, compress discards the table of substrings and rebuilds it from scratch. This allows the algorithm to adapt to the next ``block'' of the file. -c Makes compress or uncompress write to the standard output; no files are changed. The nondestructive behavior of zcat is identical to that of uncompress -c. cmp-option Specifies one of the command options for the cmp command as described in cmp(1). January 1992 1
compress(1) compress(1)compress-flag Specifies one of the command options available for compress. diff-option Specifies one of the command options for the diff command as described in diff(1). directory Specifies the starting directory within which all files are compressed or uncompressed, including those in nested directories. -f Forces compression of file. This is useful for compressing an entire directory, even if some of the files do not actually shrink. If this option is not given and compress is running in the foreground, the user is prompted as to whether an existing file should be overwritten. file Specifies the file to be affected by a compression or uncompression operation. file1 Specifies one of the pair of files to be compared by zcmp or zdiff. file2 Specifies one of the pair of files to be compared by zcmp or zdiff. uncompress-flag Specifies one of the command options available for uncompress. -v Prints a message yielding the percentage of reduction for each file compressed. -V Prints the current version and compile options on the standard output. DESCRIPTION compress and compressdir reduce the size of the named files, or the files residing under the named directories, using adaptive Lempel-Ziv coding. Whenever possible, each file is replaced by one with the extension .Z, while keeping the same ownership modes, access, and modification times. If no files are specified along with compress, the standard input is compressed to the standard output. If no directories are specified along with compressdir, the compression is applied to all files starting with the current directory. 2 January 1992
compress(1) compress(1)Compressed files can be restored to their original form using uncompress and uncompressdir along with appropriate arguments. Compressed files can be converted to an uncompressed data stream for viewing onscreen (or output redirection) by zcat (see cat(1)) and zmore (described in greater detail later in a subsequent subsection). Compressed files can be compared with one another and reports of differences can be produced by zcmp and zdiff (described later). Note that the -b option is omitted for uncompress, since the maxbits 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. The amount of compression obtained depends on the size of the input, the maximum number of bits per code, and the distribution of common substrings. Typically, text such as source code or English is reduced by 50 to 60 percent. Compression is generally much better than that achieved by Huffman coding (as used in pack) or adaptive Huffman coding (compact), and takes less time to compute. Exit status is normally 0; if the last file is larger after (attempted) compression, the status is 2; if an error occurs, exit status is 1. zmore Filter zmore is a filter which allows examination of compressed text files one group of lines at a time. It pauses after the first screenful of text and displays --More-- at the bottom of the screen. With each press of the RETURN key, one more line is displayed. With each press of the SPACE BAR, another screenful of text is displayed. The zmore program looks in the file /etc/termcap to determine terminal characteristics, and to determine the default window size. For a terminal capable of displaying 24 lines, the default window size is 22 lines for zmore. Besides entering spaces and return characters to control operation, you can enter other keys and key combinations. You can consider the --More-- message to be the command prompt for zmore. If for some reason you do not see this message (possibly after command interruption), you can type the erase character (normally by pressing DELETE) to cause the prompt to be redisplayed. It can be somewhat difficult to cancel a zmore command sequence under construction. First, the zmore command doesn't display the command entry under construction. (The January 1992 3
compress(1) compress(1)exceptions are the string seek commands and the escape-to- shell command. These commands cause your command entry to be displayed.) Second, zmore automatically recognizes when a command has been fully formed and immediately runs it (without your pressing RETURN at its end). To cancel a partially entered command sequence, you can blindly type the line kill character (normally by pressing CONTROL-U). The following list describes the effect of each of the zmore commands sequences. If an optional argument (enclosed in brackets) is not given, it normally defaults to 1. [numlines]SPACE BAR Displays the specified number of lines from the input file that occur after the last one that had been displayed previously (or another screenful if the optional argument is omitted). [numlines]CONTROL-D [numlines]d Display 11 more lines (a ``scroll''). If numlines is given, then the scroll size is the specified amount. [numlines]z Displays the specified number of lines from the input file that occur after the last one that had been previously displayed (same as a space command), except that if numlines is present, it becomes the new window size. Note that the window size reverts back to the default at the end of the current file. [numlines]s Skips the specified number of lines, then displays the next screenful of lines [numscreens]f Skips the specified number of text screens, then displays a screenful of lines q :q Q :Q Cause zmore to quit displaying the current file, skipping to the next file (if any). e Causes zmore to quit rather than continue to the next input file whenever the prompt --More--(Next file: file) appears. 4 January 1992
compress(1) compress(1)= Displays the current line number. [nth-occurrence]/regular-expr Searches for the nth occurrence of the regular expression specified. If the pattern is not found, zmore goes on to the next file (if any). Otherwise, text is displayed starting two lines before the place where the target string was found. The erase and kill characters may be used to edit the regular expression. Erasing backwards past the first column cancels the search command. [nth-occurrence]/n Searches for the nth occurrence of the previously entered regular expression (see preceding item). !command Invokes a shell to run the specified command. Any exclamation mark character (!) inside the specified command is replaced with the previous shell command specified. To allow a literally interpreted exclamation mark to be entered as part of the command line, the sequence \! is replaced by !. . (period character) Repeats the previous command. To interrupt a display action at any time, you can type the quit character (normally by pressing CONTROL-|). This causes zmore to stop sending output, but it still displays the usual prompt afterwards prompting you for one of the commands listed preceding. Note that some text is often lost when a display operation is interrupted. The terminal is set to noecho mode by this program so that the output can be continuous. As a result, the characters you type do not normally appear on your display screen (so you type commands blindly). If the standard output for zmore is redirected to a place other than the terminal, then zmore functions like zcat, except that a header is printed before each file. zcmp and zdiff File Comparers zcmp and zdiff are used to report about the differences between two files without requiring you to uncompress them first. These commands operate the same way that the corresponding commands cmp and diff operate. The command options are passed along to the cmp and diff programs, which are appropriately called by zcmp and zdiff. If only one file is specified, the files that it attempts to compare are the named one (file1) and another by the same January 1992 5
compress(1) compress(1)name but with .Z added. If two files are specified, then they are temporarily uncompressed (as necessary) and submitted to the appropriate command (cmp or diff). The exit status is the exit status from cmp or diff. STATUS MESSAGES AND VALUES Messages from the cmp or diff programs refer to temporary filenames instead of those specified. The following error messages may appear for the compress, compressdir, uncompress, or uncompressdir commands: Usage: compress [-dfvcV] [-b maxbits] [file...] Invalid options were specified on the command line. Missing maxbits maxbits must follow -b. file: not in compressed format The file specified to uncompress has not been compressed. file: already has .Z suffix -- no change The file is assumed to be already compressed. Rename the file and try again. file: filename too long to tack on .Z The file cannot be compressed because its name is longer than 12 characters. Rename and try again. file already exists; do you wish to overwrite (y or n)? Respond y if you want the output file to be replaced; n if not. The following general error messages may appear regarding the compression or uncompression process: file: compressed with xx bits, can only handle yy bits file was compressed by a program that could deal with more bits than the compress code on this machine. Recompress the file with smaller maxbits. uncompress: corrupt input A SIGSEGV violation was detected, which usually means that the input file has been corrupted. Compression: xx.xx% Percentage of the input saved by compression. (Relevant only for -v.) 6 January 1992
compress(1) compress(1)-- not a regular file: unchanged When the input file is not a regular file (for example, a directory), it is left unaltered. --has xx other links: unchanged The input file has links; it is left unchanged. See ln(1) for more information. -- file unchanged No savings is achieved by compression. The input remains virgin. LIMITATIONS Although compressed files are compatible between machines with large memory, -b 12 should be used for file transfer to architectures with a small process data space (64K or less, as exhibited by the DEC PDP series, the Intel 80286, etc.). FILES /etc/termcap Terminal data base file /usr/ucb/compress Executable file /usr/ucb/uncompress Executable file /usr/ucb/zcat Executable file SEE ALSO cat(1), cmp(1), compact(1), diff(1), more(1), pack(1) Terry A. Welch, ``A Technique for High Performance Data Compression,'' IEEE Computer, Vol. 17, No. 6 (June 1984), pages 8-19 January 1992 7