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:
.tar.Z files, at the shell prompt, enter:
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
filename.tar file, enter:
Files ending in
.gz were compressed
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:
filename with the name of the file you wish to
expand. It doesn't matter if you include the
.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,
work only on
.Z files, not
.gz files. If that seems to be true on your system, but
gzip command is installed, you can replace
gunzip -c myfile in the command above.
Files ending in
.bz2 have been compressed with
bzip2 . To decompress these files, enter one of the
bzip2 -d filename.bz2
filename with the name of the file you wish to expand.
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
At the Unix prompt, enter:
filename with the name of the zip archive.
To create a zip file, at the prompt, enter:zip filename inputfile1 inputfile2
filename with the name you want to give the zip
.zip extension is automatically appended to
the end of the filename. Replace
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
To include the contents of a directory or directories in a zip
archive, use the
directory with the name of the directory you want
to include. This will create the archive
that contains the files and subdirectories of
If, after you decompress an archive, you have a file whose name ends
.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 file has been archived using the
tar (tape archive) utility, then compressed
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):
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
is the same as indicated above.
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 zip
At 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.