How To Unzip tar.gz File? – POFTUT

How To Unzip tar.gz File?

Compression provides more disk space and network efficiency in IT systems. There are different type, level, and performance compression algorithms. tar.gz is de facto 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

tar is our old friend which 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
  • vis used for verbose mode
  • f is used for file mode

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 setup.py with the xf like below.

and extract a specific file.

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 which provides different original features. Standard input can be used for a tar.gz file. We can unzip a *.tar.gz data which 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 kernel.org and redirect to the tar command.

LEARN MORE  Linux gtar Command Tutorial with Examples and Compare with Tar

Unzip with gunzip

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.

Unzip with gunzip

Unzip with gunzip

Unzip with 7z

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.

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.

List tar.gz Contents

List tar.gz Contents

Unzip Only Specified Directory

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

Unzip Only Specified Directory

Unzip Only Specified Directory

Leave a Reply

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

Enjoy this blog? Please spread the word :)