You can compress files for storage with the compress and pack commands, and use the uncompress and unpack commands to expand the restored files. The process of compressing and expanding files takes time but, once packed, the data uses less space on the backup medium.
There are several methods of compressing a file system:
There are many reasons for compressing files, but generally they fall into two categories:
Notes:
- The command might run out of working space in the file system while compressing. The compress command creates the compressed files before it deletes any of the uncompressed files so it needs a space about 50% larger than the total size of the files.
- A file might fail to compress because it is already compressed. If the compress command cannot reduce file sizes, it fails.
The compress command reduces the size of files using adaptive Lempel-Zev coding. Each original file specified by the File parameter is replaced by a compressed file with a .Z appended to its name. The compressed file retains the same ownership, modes, and access and modification times 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.
Compressed files can be restored to their original form using the uncompress command.
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 English text is reduced by 50 to 60 percent. The compression of the compress command is generally more compact and takes less time to compute than the compression achieved by the pack command which uses adaptive Huffman coding.
For example, to compress the foo file and write the percentage compression to standard error, enter:
compress -v foo
See the compress command in theAIX Version 4.3 Commands Reference for the exact syntax.
The pack command stores the file or files specified by the File parameter in a compressed form using Huffman coding. The input file is replaced by a packed file with a name derived from the original file name (File.z), with the same access modes, access and modification dates, and owner as the original file. The input file name can contain no more than 253 bytes to allow space for the added .z suffix. If the pack command is successful, the original file is removed. Packed files can be restored to their original form using the unpack command.
If the pack command cannot create a smaller file, it stops processing and reports that it is unable to save space. (A failure to save space generally happens with small files or files with uniform character distribution.) The amount of space saved depends on the size of the input file and the character frequency distribution. Because a decoding tree forms the first part of each .z file, you do not save space with files smaller than three blocks. Typically, text files are reduced 25 to 40 percent.
The exit value of the pack command is the number of files that it could not pack. Packing is not done under any of the following conditions:
For example, to compress the files chap1 and chap2, enter:
pack chap1 chap2
This compresses chap1 and chap2, replacing them with files named chap1.z and chap2.z. The pack command displays the percent decrease in size for each file.
See the pack command in theAIX Version 4.3 Commands Reference for more information and the exact syntax.