[Next] [Previous] [Up] [Top] [Contents]

8.2 File Archiving, Compression and Conversion

8.2.1 File Compression

The compress command is used to reduce the amount of disk space utilized by a file. When a file has been compressed using the compress command, a suffix of .Z is appended to the file name. The ownership modes and access and modification times of the original file are preserved. uncompress restores the files originally compressed by compress.

Syntax

compress [options] [file]

uncompress [options] [file.Z]

zcat [file.Z]

Common Options

-c write to standard output and don't create or change any files

-f force compression of a file, even if it doesn't reduce the size of the file or if the target file (file.Z) already exists.

-v verbose. Report on the percentage reduction for the file.

zcat writes to standard output. It is equivalent to "uncompress -c".

Examples

Given the files:

96 -rw-r--r-- 1 lindadb acs 45452 Apr 24 09:13 logins.beauty

184 -rw-r--r-- 1 lindadb acs 90957 Apr 24 09:13 logins.bottom

152 -rw-r--r-- 1 lindadb acs 75218 Apr 24 09:13 logins.photon

168 -rw-r--r-- 1 lindadb acs 85970 Apr 24 09:13 logins.top

These can be compressed with:

% compress logins.*

which creates the files:

24 -rw-r--r-- 1 lindadb acs 8486 Apr 24 09:13 logins.beauty.Z

40 -rw-r--r-- 1 lindadb acs 16407 Apr 24 09:13 logins.bottom.Z

24 -rw-r--r-- 1 lindadb acs 10909 Apr 24 09:13 logins.photon.Z

32 -rw-r--r-- 1 lindadb acs 16049 Apr 24 09:13 logins.top.Z

The original files are lost.

To display a compressed file, the zcat command is used:

% zcat logins.beauty.Z | head

beauty:01/22/94:#total logins,4338:#different UIDs,2290

beauty:01/23/94:#total logins,1864:#different UIDs,1074

beauty:01/24/94:#total logins,2317:#different UIDs,1242

beauty:01/25/94:#total logins,3673:#different UIDs,2215

beauty:01/26/94:#total logins,3532:#different UIDs,2216

beauty:01/27/94:#total logins,3096:#different UIDs,1984

beauty:01/28/94:#total logins,3724:#different UIDs,2212

beauty:01/29/94:#total logins,3460:#different UIDs,2161

beauty:01/30/94:#total logins,1408:#different UIDs,922

beauty:01/31/94:#total logins,2175:#different UIDs,1194

A display of the file using commands other than zcat yields an unreadable, binary, output.

The uncompress command is used to return the file to its original format:

% uncompress logins.*.Z ; ls -als logins.*

96 -rw-r--r-- 1 lindadb acs 45452 Apr 24 09:13 logins.beauty

184 -rw-r--r-- 1 lindadb acs 90957 Apr 24 09:13 logins.bottom

152 -rw-r--r-- 1 lindadb acs 75218 Apr 24 09:13 logins.photon

168 -rw-r--r-- 1 lindadb acs 85970 Apr 24 09:13 logins.top

In addition to the standard Unix compress, uncompress, zcat utilities there are a set of GNU ones freely available. These do an even better job of compression using a more efficient algorithm. The GNU programs to provide similar functions to those above are often installed as gzip, gunzip, and zcat, respectively. Files compressed with gzip are given the endings .z or .gz. GNU software can be obtained via anonymous ftp from ftp://prep.ai.mit.edu/pub/gnu.


Introduction to Unix - 14 AUG 1996
[Next] [Previous] [Up] [Top] [Contents]