Extract tar.gz File

by on February 8, 2008 · 18 comments· LAST UPDATED November 10, 2013

in , ,

I have downloaded a file called foo.tar.gz from the Internets. How do I extract tar.gz file under Linux / UNIX like operating systems using command line options?

A tarball (tar.gz file) is nothing but compressed tar archive.

The tar program provides the ability to create tar archives, as well as various other kinds of manipulation. For example, you can use Tar on previously created archives to extract files, to store additional files, or to update or list files which were already stored.

Tutorial details
DifficultyEasy (rss)
Root privilegesNo
Estimated completion time2m
Initially, tar archives were used to store files conveniently on magnetic tape. The name "Tar" comes from this use; it stands for tape archiver. Despite the utility's name, Tar can direct its output to available devices, files, or other programs (using pipes), it can even access remote devices or files (as archives). The tar command is available on Linux (CentOS/RHEL/Fedora/Debian/Ubuntu and all other distros), BSD (OpenBSD/NetBSD/FreeBSD), Apple OS X, HP-UX, AIX, and other Unix like operating systems.


The syntax is as follows:

tar options file.tar.gz
tar options file.tar.gz pattern
tar -xf file.tar.gz
tar -xvf file.tar.gz
tar -zxvf file.tar.gz
tar -zxvf file.tar.gz file1 file2 dir1 dir2

Extract tr.gz. file

To extract one or more members from an archive, enter:
$ tar -zxvf {file.tar.gz}
If your tarball name is backup.tar.gz, enter the following at a shell prompt to extract files:
$ tar -zxvf backup.tar.gz
To extract resume.doc file from backup.tar.gz tarball, enter:
$ tar -zxvf backup.tar.gz resume.doc

  1. -z : Work on gzip compression automatically when reading archives.
  2. -x : Extract archives.
  3. -v : Produce verbose output i.e. display progress and extracted file list on screen.
  4. -f : Read the archive from the archive to the specified file. In this example, read backups.tar.gz archive.
  5. -t : List the files in the archive.

Extracting an entire archive

To extract an entire archive, specify the archive file name only, with no individual file names as arguments.
tar -zxvf backup.tar.gz

List files in archive

To view a detailed table of contents (list of file), enter::
$ tar -tvf backup.tar.gz

See also
Tweet itFacebook itG+ itDownload PDF versionFound an error/typo on this page?

{ 18 comments… read them below or add one }

1 anish December 11, 2008 at 10:10 am

use the followinf command:
tar -xvf


2 Kartik April 11, 2011 at 1:18 pm

Directory Checksum error.

Using on SunOS 2.6


3 Khupcom November 16, 2010 at 2:35 am

How to extract without screen output?


4 anon November 28, 2010 at 8:04 am

tar -zxf,
ie leave out ‘v’, it stands for verbose


5 william post January 26, 2011 at 3:54 pm

I kept leaving the f (for file) out and tar would just sit there!


6 Andkon April 30, 2011 at 5:06 am

Great sharing. I really appreciate the idea you gave! Lots of thanks!


7 wupload June 27, 2011 at 12:01 pm

great share thnx man


8 Parasuraman P June 30, 2011 at 6:02 am

its very useful for linux user….thanks


9 M. K. Goenka October 14, 2011 at 5:05 am

when I am trying to tar a .tar.gz file using the all kind of command as ststed above it is showing that 1) tar: child returned status 1
2) tar: errors exit delayed from previous error
using centos 64 bit OS


10 Gangadhar January 20, 2012 at 12:53 pm

It is working in AIX if you give as tar -zxvf *.tar.gz (Actual Tar file)


11 ahmad March 21, 2012 at 8:00 pm

really a good post


12 iplixler October 25, 2012 at 11:12 am

I want to extract sysbench- that i wget from SourceForge but got this error. Please help.

[root@cdn temp]# tar -zxvf sysbench-
tar: This does not look like a tar archive
tar: Skipping to next header
tar: Exiting with failure status due to previous errors


13 Surya Haris Senoaji January 14, 2013 at 4:01 pm

I have the same problem when trying to extract flashplayer 11 plugin, help please.. :'(

tar: install_flash_player_11_linux.x86_64.tar.gz: Cannot open: No such file or directory
tar: Error is not recoverable: exiting now
tar: Child returned status 2
tar: Exiting with failure status due to previous errors


14 dinesh August 25, 2014 at 2:52 am

in that case .. just use tar -xf


15 ajay gadhavana June 27, 2013 at 9:56 am

its normal error.
its due to your file is another location and you try to extract from other location.
please first check file is exist in same directory or not?

ajay gadhavana


16 Irwan October 29, 2013 at 11:42 am

I extract the file using 7-Zip software… can just download the software


17 John January 3, 2014 at 10:35 pm

Also a great tip i learned for extracting.
Sometimes you just need to extract the contents into the same directory.
Most tared up files have a container folder.
To simply overide that just type “–strip 1″ at the end of the command.

$ tar -zxvf backup.tar.gz --strip 1

You Welcome!


18 Don February 11, 2015 at 4:00 pm

This is something I feel is missed on every explanation of using tar with compression.

The options must be done in order. for example to create a compressed tarball using xz, you would do -Jcvf or gz would be -jcvf. j or J is the compression. c means create, v is verbose, which you don’t need to do, and f is, name it the following name.

HOWEVER, if you did, -xvfj, it would create an error, because the options must be in order. The first letter has to be the type of compression. The next letter is what to do, as in compress or extract. Followed by misc options which can consist of verbose etc. and the last letter should be f if you are naming the file something.

Many programs do not care what order you put options in, but tar does.

So, compression type : what to do : misc options : how are you handling it, like name it this file.


Leave a Comment

Tagged as: , , , , , , , , , , ,

Previous Faq:

Next Faq: