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 | |
---|---|
Difficulty | Easy (rss) |
Root privileges | No |
Requirements | tar |
Time | 2m |
Syntax to extract .tar.gz file
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
Extracting 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
Where,
- -z : Work on gzip compression automatically when reading archives.
- -x : Extract tar.gz archive.
- -v : Produce verbose output i.e. display progress and extracted file list on screen.
- -f : Read the archive from the archive to the specified file. In this example, read backups.tar.gz archive.
- -t : List the files in the archive.
- -r : Append files to the end of the tarball.
- --delete (GNU/Linux tar only) : Delete files from the tarball.
In order to untar a tar file, the -x (for extract) and -f options are needed.
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 list of the files within a tarball, issue the following command, enter:
$ tar -tvf backup.tar.gz
How to create a tarball
tar command used to create a Tape ARchive. The resulting file is known as a tarball in Unix world. Let us see how to create a tarball using tar command. The following would create an archive file called data.tar from the three files named file1.txt, file2.txt and file3.txt that are located in the current directory:
tar -cvf data.tar file1.txt file2.txt file3.txt
One can use the tar command to make archives from the contents of one or more directories. For example, the contents of two directories named /etc/ and /home/vivek/Documents/ could be archived into a file named dump.tar with the following:
tar -cvf dump.tar /etc/ /home/vivek/Documents
In this example, create an archive named data.tar.bz2 of the files /etc/ directory that is compressed using gzip:
tar -cvzf files.tar.gz /etc/
How to add files to an existing tarball
Pass the -r option. For example, the following would append a file named resume.doc to file.tar:
tar -rf file.tar resume.doc
How delete files from a tarball
Pass the --delete option to GNU/tar command which allows specified files to be completely removed from a tarball. Thus, for example, the files pic1.png and pic2.png can be removed from file.tar with the following:
tar -f file.tar --delete pic1.png pic2.png
Conclusion
We have shown you how to extract tar.gz file from the command line. The commands should work on Linux and Unix-like systems. For more info see tar command help page here and here.
🐧 Get the latest tutorials on Linux, Open Source & DevOps via:
- RSS feed or Weekly email newsletter
- Share on Twitter • Facebook • 19 comments... add one ↓
Category | List of Unix and Linux commands |
---|---|
File Management | cat |
Firewall | Alpine Awall • CentOS 8 • OpenSUSE • RHEL 8 • Ubuntu 16.04 • Ubuntu 18.04 • Ubuntu 20.04 |
Network Utilities | dig • host • ip • nmap |
OpenVPN | CentOS 7 • CentOS 8 • Debian 10 • Debian 8/9 • Ubuntu 18.04 • Ubuntu 20.04 |
Package Manager | apk • apt |
Processes Management | bg • chroot • cron • disown • fg • jobs • killall • kill • pidof • pstree • pwdx • time |
Searching | grep • whereis • which |
User Information | groups • id • lastcomm • last • lid/libuser-lid • logname • members • users • whoami • who • w |
WireGuard VPN | Alpine • CentOS 8 • Debian 10 • Firewall • Ubuntu 20.04 |
use the followinf command:
tar -xvf
Directory Checksum error.
Using on SunOS 2.6
How to extract without screen output?
tar -zxf,
ie leave out ‘v’, it stands for verbose
Cool!
I kept leaving the f (for file) out and tar would just sit there!
Great sharing. I really appreciate the idea you gave! Lots of thanks!
great share thnx man
its very useful for linux user….thanks
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
It is working in AIX if you give as tar -zxvf *.tar.gz (Actual Tar file)
really a good post
I want to extract sysbench-0.4.12.5.tar.gz that i wget from SourceForge but got this error. Please help.
[root@cdn temp]# tar -zxvf sysbench-0.4.12.5.tar.gz
tar: This does not look like a tar archive
tar: Skipping to next header
tar: Exiting with failure status due to previous errors
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
in that case .. just use tar -xf
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?
thanks
ajay gadhavana
I extract the file using 7-Zip software… can just download the software
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.
You Welcome!
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.
Rather than extracting, how would you simply display the contents of an individual file in a tar.gz?