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:

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:

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:

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:

Leave a Reply

Your email address will not be published. Required fields are marked *