Previous Table of Contents Next


Module 98
pack/unpack (SV)

DESCRIPTION

The external pack command compresses the data stored in a file. It attempts to reduce the size of a file by compressing the data within the file. When a successful compression of data has occurred, the original file name is replaced by the new packed file with a name of name.z. Typical compression reduces the file size by 25 to 40 percent.

The external unpack command unpacks a previously packed file. It reverses the effects of the pack command. It takes a name.z file for input and creates an unpacked name file.

COMMAND FORMAT

Following is the general formats of the pack command.

       pack [ - ] [ -f ] [ file_list ]
       unpack file_list

Options

The following list describes the options that may be used to control how pack functions.

- Causes pack to toggle the displaying of status information about the compression algorithm on or off. The first occurrence toggles the information on, the number of times a byte is used, its relative frequency, and the code for the byte are displayed. The - option may be placed between names to toggle the information on and off. For example,

pack - afile - myfile

would display the status information for afile but would not display it for myfile.

-f Forces the compression of the data even if pack realizes there is no saving of space. This may prove useful if you want all files in a directory to be packed so you don't have a mix of different file formats and names.

Arguments

The following argument may be passed to the pack command.

file_list The name of the file you wish to pack. Multiple names may be supplied on the command line. Names must not exceed 80 characters. Two additional characters (.z) are placed at the end of each name that is packed.

The following argument is used by unpack.

file_list One or more files to be unpacked. The names may be name or name.z.

FURTHER DISCUSSION

The pack command becomes more efficient the larger the files. Target files for packing are text files with more than three blocks of data. Object and binary files usually do not compress more than 10 percent, whereas text files may compress up to 50 percent.

The pack command may not compress the data in a file for several reasons. The following list explains each reason.

The file appears to be packed already.
The filename has more than 80 characters.
The file has links. pack could only change one of the filenames, leaving other filenames without the .z extension pointing to packed data.
The file is a directory.
The file cannot be opened (it's not readable).
The compression of the file will not save any disk space.
A compressed file with the same name.z already exists.
The name.z file cannot be created (you do not have write permissions).
Some type of I/O error occurred while pack was compressing the data.

NOTE:  
Directories cannot be packed.



The unpack command may fail if any of the following conditions occur.

The file does not appear to be a packed file.
The filename provided has more than 80 total characters, including the .z.
The file cannot be opened.
The unpacked version of the filename exists (name).
The unpacked file cannot be created.

RELATED COMMANDS

Refer to the pcat command described in Module 102.

RELATED FILES

The pack command displays status messages to the standard output if the - option is toggled on.

The filenames used on the command line that are to be packed must contain 80 characters or less.

The unpack command unpacks files with a filename of name.z. It can accept arguments of name or name.z.

RETURN CODES

The pack command returns an exit status equal to the number of files it failed to pack. The unpack command returns an exit status equal to the number of files it failed to unpack.

APPLICATIONS

You use the pack command to reduce the disk space required to store your commands. Usually, you pack files that are not changed very often.

The unpack command is used only to unpack files previously packed by the pack command. Usually, you only use unpack if you want to make changes to the data stored in the packed file. If you only need to view the contents, you should use the pcat command.

TYPICAL OPERATION

In this activity you use the pack command to compress your copy of the password file. Begin at the shell prompt.

1.  Type cp /etc/passwd passwd and press Return.
2.  Type pack - passwd and press Return. The status information is displayed on your screen. Notice the pack command informs you on the percentage of compression gained by the pack.

In this activity you use the unpack command to unpack the previously packed passwd file. Begin at the shell prompt.

1.  Type unpack passwd.z and press Return. The passwd file is unpacked and the filename changed to passwd. If you have doubts, you can cat the unpacked file to view the contents.
2.  Turn to Module 102 to continue the learning sequence.


Previous Table of Contents Next