Abbey Workshop

Unzipping a File Using gunzip and tar

In UNIX and Linux, files are compressed and stored using the GNU zip utilities. Often, if a directory containing a number of files needs to be compressed, it is first stored in a single file using tar. The tar command was originally used to make tape archives, but is still commonly used to store many files into one file. You can combine the gzip utilities with tar on one line to simplify your commands.

For example, to uncompress the file foo.tar.gz you could use one of the following commands:

gunzip -c foo.tar.gz | tar xvf -

or alternatively:

gunzip < foo.tar.gz | tar xvf -

Both commands write the data produced from the gunzip command to standard out. (-c in the first example and using < in the second), using a pipe, the data is used as input in the tar command. The dash "-" represents standard input.

Zipping

Since you can unzip, you can also zip with a single command. For example, to zip the foodir directory into the foo.tar.gz archive you can use the following command:

tar cvf - foodir | gzip > foo.tar.gz