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:
uncompress filename.Z
Use the ls
command to check the resulting files. If uncompress
creates a .tar
file, you must extract the files by entering:
tar -xvf filename.tar
Alternatively, to do this in one step and avoid creating the intermediate filename.tar
file, enter:
zcat filename.Z | tar -xvf -
.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 one of these files, at the Unix prompt, enter:
gunzip filename
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:
zcat myfile | more
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
bzip2 -d filename.bz2
Replace filename
with the name of the file you wish to expand.
.zip
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:
unzip filename
Replace filename
with the name of the ZIP archive.
To create a ZIP file, at the prompt, enter:
zip filename inputfile1 inputfile2
Replace 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:
zip -r filename directory
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 Use tar to combine multiple files into an archive file .
.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):
zcat file.tgz | tar xvf -
Replace file.tgz
with the name of your file.
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 zip
At Indiana University, for personal or departmental Linux or Unix systems support, see Get help for Linux or Unix at IU.
This is document aeqx in the Knowledge Base.
Last modified on 2023-09-28 16:10:13.