Most of the software, documents, files, etc. in Linux are archived in the tar.gz format instead of the zip or rar formats usually used in Windows, though Linux utilities support these formats.

tar.gz format is popularly used by software available for Linux both in official repositories as well as unofficially over the Internet.

What is a tar.gz file?

tar.gz (Gzip) is one of the file formats available in tar compression system. Some other file formats are bz2, lzip and lzop. Gzip and bz2 are the most commonly used formats. Gzip is meant for faster compression, whereas bz2 is meant for a lesser archive size.

tar is by default installed on most Linux systems. In case it is missing, you can install it on Ubuntu, Debian or similar Linux distributions by running:

sudo apt install tar

Note: In case of Ubuntu version < 14.04, use apt-get instead of apt.

To install tar on CentOS and Fedora, run:

yum install tar

How to extract tar.gz using tar command

To extract a tar.gz archive file, run:

tar xvzf <archive_filename>.tar.gz

Let us see what the options xvzf mean:

x – Specifies that files are to be extracted from the archive.

v – Stands for verbose. Print each filename extracted from the archive along with its path. This is meant only for information, and hence is not mandatory.

z – This specifies that the archive is compressed with Gzip

f – This specifies that the following argument after the options is going to be the name of the archive file to be extracted. If this option is not provided, tar tries to read from the terminal standard input. In more recent versions, it throws an error whenever this option is not specified.


The following command will extract the three files in the archive testarchive.tar.gz and print their names.

tar xvzf testarchive.tar.gz

As we can see the three files have been extracted. Note that the command extracts the file in the same folder from where the command is run.