How to extract .tar.gz files using command line in Linux?

Leave a comment on How to extract .tar.gz files using command line in Linux?

Tar works just the same as .Zip archive. We use one type of archive format to compress and store multiple files or directories into one file formatted with the .tar.gz extension. The Linux platform has .tar.gz is the most common utility to compress the files for backups and it uses Gzip which is the most common algorithm to compress the tar files. It can compress every file type, including text files, videos, mp3, etc. We will demonstrate how you can use and extract the .tar.gz files using the command line in Linux. Let’s go!

Tar command’s standard format,

tar [OPTION…] [FILE]…

Let’s break down the tar command,

[OPTION]: Options are nothing but the variables we use to extend the uses of the tar command. Following are the most common variables/options we use with the tar command,

-A, –catenate, –concatenate: Append tar files to an archive.

-c, –create : Create a new archive.

-d, –diff, –compare: Find differences between archive and file system.

–delete: Delete from the archive (not on mag tapes!).

-r, –append: Append files to the end of an archive.

t, –list: List the contents of an archive.

–test-label: Test the archive volume label and exit.

-u, –update: Only append files newer than copy in the archive.

x, –extract, –get: Extract files from an archive.

-v: Verbose.

-z: Guides the tar command to uncompress the file (gzip).

-f: To indicate the file name to the tar command.

[FILE]: It’s the directory/file which we will be extracting/compressing using the tar.

So far we understood the options and how tar command words. To extract the files from the .tar.gz (Gzip file) file use the following command,

tar xzf [FILE]


tar xzf racknerd.tar.gz

extract tar gz xzf

In case, if you want to view the extracted contents of the file then you need to use “v” (verbose) as a variable with tar command,

tar xvzf [FILE]


tar xvzf racknerd.tar.gz

tar xzvf extract files

By default, extracting the tar.gz file should extract the files at the present location (You can check the working directory path using the pwd command). To extract the files to a specific location, you need to use the -C argument following with directory path,

tar xvzf [FILE] -C [PATH]


tar xvzf racknerd.tar.gz -C /home/nerd/customlocation

tar xvzf c to extract files at specific location

Before extracting the files, you might need to check the compressed file contents in many cases. To vire the contents of the .tar.gz file, you can use the following command with the argument -t.

tar tvf [FILE]


tar tvf racknerd.tar.gz

tar tvf extract file

Furthermore, we have two more types of files .gz and .tar.bz2 (If the files are compressed with a bz2 compressor). Let’s learn how you can extract both of them,

To extract the .gz file run the following command,

gunzip [FILE]


gunzip racknerd.gz

gunzip tar file

To extract the .tar.bz2 file, which is compressed with a bz2 compressor,

tar xvjf [FILE]


tar xvjf nerd.tar.bz2

extract bz2 files

Server Hosting Solutions by RackNerd:

Shared Hosting
cPanel Web Hosting in US, Europe, and Asia datacenters
Reseller Hosting
Create your new income stream today with a reseller account
VPS (Virtual Private Server)
Fast and Affordable VPS services - Instantly Deployed
Dedicated Servers
Bare-metal servers, ideal for the performance-demanding use case.

Leave a comment

Your email address will not be published.