In this article you will learn how to extract/untar tar.gz files in Linux systems through the command line using the tar command.
A lot of the downloadable Linux/Unix files found on the internet are compressed using a tar.gz format. Therefore, knowing how to open or untar tar.gz files is a very useful skill.
The name “Tar” stands for “Tape Archiver”, because when tar was invented it was used to place data on storage tapes. A .tar.gz file is nothing, but an archive. The tar program takes one or more files and “wraps” them into a self-contained file.
To untar tar.gz files just means to extract the contents of the tar file (also known as a tarball).
People new to the .tar format usually equate it to a .zip archive, but a tar archive is not compressed. Tar collected all the files into one package, but the files can be compressed with separate utilities.
Gzip is the most popular algorithm for compressing tar files. By convention, the name of a tar archive compressed with gzip becomes .tar.gz or .tgz.
To put it simple: a file that ends in .tar.gz is just a .tar archive compressed with gzip.
How to Untar a tar.gz File
Most Linux distributions comes with
tar command pre-installed by default.
To untar tar.gz file enter the following:
tar xvzf file.tar.gz
Let’s break down this syntax. Here is what each parameter in that command means:
x: This option tells tar to extract the files.
v: Verbose output shows you all the files being extracted.
z: Tells tar to decompress the archive using gzip.
f: This must be the last flag of the command. It tells tar the name and path of the compressed file.
How to Untar a tar.gz File to a Different Directory
To uncompress tar.gz file and put resulted files in a different directory, say
/tmp/archive, you need to add a
-C option at the end of the command:
tar xvzf file.tar.gz -C /tmp/archive
-C option is used to specify a different directory other than the current working directory.
Now you know how to untar a tar.gz file in Linux. Perhaps you might also be interested in learning about how to unzip files in Linux.
For more about
tar command in Linux, consult its manual page.
If you find this article helpful or have additional ideas, please feel free to use the comment box below.