How to Extract (Unzip) Tar Gz File

Gzip is the most popular algorithm for compressing tar files. By convention, the name of a tar archive compressed with gzip ends with either .tar.gz or .tgz.

In short, a file that ends in .tar.gz is a .tar archive compressed with gzip compression algorithm. In this tutorial, I will show you how to extract or unzip tar.gz and tgz archives.

Extracting (Unzip) Tar Gz (tar.gz) File

Most Linux distributions and MACOS comes with tar command pre-installed by default.

To extract a tar.gz file, use the –extract (-x) operator and specify the archive file name after the f option:

tar -xf archive.tar.gz

The tar command auto-detects compression type and extracts the archive. The same tar command can be used to extract tar archives compressed with other algorithms such as .tar.bz2.

With command you can pass -v option to make it print more verbose information such as file name being extracted and other info. Use:

tar -xvf archive.tar.gz

You can pass the -C option to specify directory to which you want to extract files. By default tar will extract files to current working directory. Example:

By default, tar will extract the archive contents in the current working directory. Use the –directory (-C) to extract archive files in a specific directory:

tar -xf archive.tar.gz -C /home/inimist/unzipped

Extracting selected files from a tar.gz file

You can pass specific file names after the archive.tar.gz name to extract only those files. For example:

tar -xf archive.tar.gz file1 file2

Leave a Reply