compress, uncompress, or zcat Command Purpose Compresses and expands data. Syntax To Compress a File compress [ -c ] [ -C ] [ -d ] [ -F ] [ -f ] [ -n ] [ -q ] [ -v ] [ -V ] [ -b Bits ] [ File ... ] To Expand a Compressed File uncompress [ -c ] [ -F ] [ -f ] [ -n ] [ -q ] [ -v ] [ File ... ] To Expand the Standard Input zcat [ -F ] [ -f ] [ -n ] [ File ... ] Description The compress command reduces the size of files using adaptive Lempel-Zev coding. Each original file specified by the File parameter is replaced when possible by a compressed file with a .Z appended to its name. The compressed file retains the same ownership, modes, and modification time of the original file. If no files are specified, the standard input is compressed to the standard output. If compression does not reduce the size of a file, a message is written to standard error and the original file is not replaced. Note: Files must have correct permissions to be replaced. The uncompress command restores original files that were compressed by the compress command. Each compressed file speci- fied by the File variable is removed and replaced by an expanded copy. The expanded file has the same name as the compressed ver- sion, but without the .Z extension. If the user has root au- thority, the expanded file retains the same owner, group, modes, and modification time as the original file. If the user does not have root authority, the file retains the same modes, and modifi- cation time, but acquires a new owner and group. If no files are specified, standard input is expanded to standard output. Although similar to the uncompress command, the zcat command al- ways writes the expanded output to standard output. The compress command uses the modified Lempel-Zev algorithm popu- larized in "A Technique for High Performance Data Compression," Terry A. Welch, IEEE Computer, vol. 17, no. 6 (June 1984), pp. 8-19. The amount of compression depends on the size of the input, the number of bits per code specified by the Bits variable, and the distribution of common substrings. Typically, source code or En- glish text is reduced by 50 to 60%. The compression of the compress command is generally more compact and takes less time to compute than the compression achieved by Huffman coding (as used in the pack command) or adaptive Huffman coding. Flags -d Makes the compress command function exactly like the uncompress command. The -d flag can be specified only with the compress command. -f Forces compression or expansion of the file specified by the File parameter. When used with the compress command, the -f flag overwrites the File.Z file if it already exists. When used with the uncompress command, the -f flag overwrites the file if it al- ready exists. The user is not prompted that an existing file will be overwritten. File size may not actually shrink. -F Functions the same as the -f flag. -c Makes the compress or uncompress command write to standard output; no files are changed. The nondestructive behavior of the zcat command is identical to that of the uncompress -c command. -C Produces output compatible with the BSD compress command, Re- vision 2.0. -b Bits Specifies the maximum number of bits to use to replace common substrings in the file. The Bits variable value must be in the range from 9 bits through 16 bits, with the default being 16 bits. When compressing data, the algorithm first uses all of the 9-bit codes (257 through 512) to replace as many substrings as possible. Then it uses all 10-bit codes, and so on, continu- ing until the limit specified by the -b flag is reached. The -b flag is not permitted with the uncompress command. After the Bits limit is attained, the compress command periodi- cally checks the compression ratio. If it is increasing, the compress command continues to use the existing code dictionary. However, if the compression ratio decreases, the compress command discards the table of substrings and rebuilds it. Rebuilding the table allows the algorithm to adapt to the next block of the file. -n Omits the compressed file header from the compressed file. -q Suppresses the display of compression statistics generated by the -v flag. If several -v and -q flags are on the same command line, the last one specified controls the display of the statis- tics. -v Writes the percentage of compression for the compress command. -V Writes the current version and compile options to standard er- ror. Return Values If an error occurs the exit status is 1. If the compress command exits without compressing a file, it exits with a status of 2. Otherwise, the compress, uncompress, or zcat command exit with a status of 0. The compress command will detect an error and exit with a status of 1 if any of the following events occur: * An input file is not a regular file. * An input file name is too long to append the .Z extension. * An input file cannot be read or an output file cannot be writ- ten. The uncompress and zcat commands will detect an error and exit with a status of 1 if any of the following events occur: * The input file was not produced by the compress command. * An input file cannot be read or an output file cannot be writ- ten. Exit Status The following exit values are returned for the compress command: 0 Successful completion. 1 An error occurred. 2 One or more files were not compressed because they would have increased in size (and the -f option was not specified). >2 An error occurred. The following exit values are returned for the uncompress and zcat commands: 0 Successful completion. >0 An error occurred. Examples To compress the foo file and write the percentage compression to standard error, enter: compress -v foo Implementation Specifics These commands are part of Base Operating System (BOS) Runtime. Related Information Commands Overview in AIX Version 3.2 System User's Guide: Operating System and Devices. The pack command, unpack command.