About compressed files in Unix
Compressed files take up less disk space than normal files, but you cannot read them in the usual way; you must first expand, or decompress, the files. How you do that depends on the program used to compress the file in the first place. See the appropriate section below for your compressed file's extension.
On this page:
.Z or .tar.Z
To extract .Z
or .tar.Z files, at the shell prompt, enter:
Use the ls command to check the resulting files. If
uncompress creates a .tar file, you must
extract the files by entering:
Alternatively, to do this in one step and avoid creating the
intermediate filename.tar file, enter:
.z or .gz
Files ending in .z or .gz were compressed
with gzip, a newer and improved program. (At Indiana University, gzip is installed on UITS
shared Unix systems.) To decompress a
gzipped file, at the Unix prompt, enter:
Replace filename with the name of the file you wish to
expand. It doesn't matter if you include the .z or
.gz in the filename.
If you don't have enough disk space to decompress the file, or you
only want to see the contents once and have the file stay compressed,
you can send the contents of the file to the standard output (usually
your terminal), by using the zcat command. For example,
to read the decompressed contents of myfile.gz one page
at a time, enter:
Note: On some Unix systems, zcat may
work only on .Z files, not .z or
.gz files. If that seems to be true on your system, but
the gzip command is installed, you can replace zcat
myfile with gunzip -c myfile in the command above.
.bz2
Files ending in .bz2 have been compressed with
bzip2 . To decompress these files, enter one of the
following commands:
bunzip2 filename.bz2
or
bzip2 -d filename.bz2
Replace filename with the name of the file you wish to expand.
.zip
Note: Files created by zip can normally be decoded by programs
such as WinZip and StuffIt Expander.
To decompress a zip file in Unix, use the unzip command.
At the Unix prompt, enter:
Replace filename with the name of the zip archive.
To create a zip file, at the prompt, enter:
zip filename inputfile1 inputfile2Replace filename with the name you want to give the zip
file. The .zip extension is automatically appended to
the end of the filename. Replace inputfile1 and
inputfile2 with the names of the files you wish to
include in the zip archive. You can include any number of files here,
or you may use an asterisk (*) to include all files in the current
directory.
To include the contents of a directory or directories in a zip
archive, use the -r flag:
Replace directory with the name of the directory you want
to include. This will create the archive filename.zip
that contains the files and subdirectories of directory.
.tar
If, after you decompress an archive, you have a file whose name ends
in .tar, you now have a tar (short for "tape archiving")
archive, which is a way of collecting together several files, or even
entire directories. For more, see In Unix, what is tar, and how do I use it?
.tgz
A .tgz file has been archived using the
tar (tape archive) utility, then compressed
using gzip. The gzip utility is an
alternative to the compress program on Unix computers,
and yields slightly better performance.
To decompress and unarchive the file at the same time, use the
zcat program, which sends a gzipped file to "standard
out" (the terminal):
Replace file.tgz with the name of your file.
Note: A file ending in .taz also has
been tarred and gzipped, but is of an older file naming standard. The
procedure for decompressing and unarchiving a .taz file
is the same as indicated above.
Additional information
For more information about the commands discussed above, you can refer to the Unix man pages. At the Unix prompt, enter one of the following:
man uncompress man gzip man zcat man tar man bzip2 man unzip man zipAt Indiana University, for personal or departmental Linux or Unix systems support, see At IU, how do I get support for Linux or Unix?
Last modified on February 15, 2011.







