Extract files from tar archive in Linux
5
It is absolutely impossible to memorize tar command line options!
tar.gz
To extract files from the tar.gz
(gzipped tarball) archive type the following:
tar -zxvf archive.tar.gz
tar.bz2
If your tarball is compressed with bzip2 instead of gzip, then use j
switch instead of z
:
tar -jxvf archive.tar.bz2
Just tar
If your archive isn't compressed at all but just a tarball then you don't need z
either j
switches:
tar -xvf archive.tar
Different destination
To extract files into different folder add -C
option:
tar -C /home/sam/folder -zxvf archive.tar.gz
Extract a single folder
To extract a single folder, let's say /home/sam/blog
use the following:
tar -zxvf archive.tar.gz home/sam/blog
Extract a single file
To extract a single file, let's say /home/sam/blog/entry1.txt
use the following:
tar -zxvf archive.tar.gz /home/sam/blog/entry1.txt
Rate this post:
Share this page:
See also how to:
How to create TAR archive in PHP, compress it as Gzip or Bzip2, or extract files from it
How to extract files from zip archive in Linux command line
How to pretty print XML documents on Linux
How to run your PHP or Bash script as root in the most secure way
How to install PHP FastCGI Process Manager (FPM) on CentOS 7