How To Unzip tar.gz File?

Compression provides more disk space and network efficiency in IT systems. There are different types, levels, and performance compression algorithms. tar.gz is defacto standard for Linux systems for a long time. In this tutorial, we will look at different ways to unzip or uncompress tar.gz files.

Unzip with tar Command

tar is our old friend who can provide compress and decompress of a lot of different compression formats. We will unzip test.tar.gz in this example with x,v  and f options.

  • x is used to extract
  • v is used for verbose mode
  • f is used for file mode
$ tar xvf test.tar.gz
Unzip with tar
Unzip with tar

Extract Specific File From A tar.gz

We can extract a specific file from an *.tar.gz archive. We will just provide the file or directory name we want to extract to the end of the command. First listing the contents of the *.tar.gz file content and then providing the file name precisely. We will list file contents with the -tf option and extract the file named with the xf like below.

$ tar -tf zipstream-1.1.4.tar.gz

and extract a specific file.

$ tar -xf zipstream-1.1.4.tar.gz zipstream-1.1.4/
Extract Specific File From A tar.gz
Extract Specific File From A tar.gz

Unzip From Stdin or Standard Input

Linux is a very elastic operating system that provides different original features. Standard input can be used for a tar.gz file. We can unzip a *.tar.gz data that will be fed from the standard input. We will use the | in order to redirect the file to the tar command. In this example, we will download the Linux kernel from and redirect it to the tar command.

$ wget -c -O - | tar -xz

Unzip with gunzip Command

gunzip is the unzip command provided by gzip suite. We can use this command without any option in order to unzip. But in this example, we use -voption which is used for verbose mode.

$ gunzip -v test.tar.gz

Unzip with 7z Command

7z  is my favorite compression algorithm and tool. It supports a lot of formats from zip to rar. gz format is also supported. We can provide e option in order to extract the tar.gz . 7z automatically detects the format.

$ 7z e test.tar.gz
Unzip with 7z
Unzip with 7z

List tar.gz Contents

If we want to unzip only some of the files from a tar.gz archive first we need to list files. We can list files different ways but we will look only single command which is tar.

 $ tar tvf test.tar.gz
List tar.gz Contents
List tar.gz Contents

Unzip Only Specified Directory

If we need to extract only some of the files or directories we need to specify them. We will use unzip command and provide the files and directories at the end of the command we want to extract. In this example, we will extract the file oldbackup/db.conf file from tar.gz file.

$ tar xvf test.tar.gz oldbackup/db.conf

LEARN MORE  Linux ar Command Tutorial with Examples For Archiving

Leave a Comment