Uncompress tar.gz - Linux Command Line

  • redgtsviper
  • Novice
  • Novice
  • redgtsviper
  • Posts: 19

Post 3+ Months Ago

I have a file called file.tar.gz. How can I uncompress this file on a Redhat server from command line? I want all the files extracted the the current directory that I am in. I imagine this would work for Linux or Unix.
  • Bigwebmaster
  • Site Admin
  • Site Admin
  • User avatar
  • Posts: 9105
  • Loc: Seattle, WA & Phoenix, AZ

Post 3+ Months Ago

There is more than one way to do this, however I tend to do it like this from command prompt:

Uncompress tar.gz


The below does both the uncompressing and untarring in a single command and puts the contents in the same directory you are in:
Code: [ Select ]
tar zxvf file.tar.gz

The z argument basically does the gunzip work for you.

Uncompress tar.gz into different directory


Use the -C argument to specify the path to place the files:
Code: [ Select ]
tar zxvf file.tar.gz -C /path/to/somedirectory


Uncompress first, untar second


When you uncompress first using gunzip, it will strip the .gz file extension from the file leaving you with a .tar file:
Code: [ Select ]
gunzip file.tar.gz
tar xvf file.tar
  1. gunzip file.tar.gz
  2. tar xvf file.tar


Uncompress tar.bz2


You might also encounter a bz2 file that you need to uncompress and untar:
Code: [ Select ]
tar xvjf file.tar.bz2


Common Tar Arguments


With tar some of the arguments we used above mean the following:

Code: [ Select ]
x - extract
v - verbose output
j - filter the archive through bzip2
f - read from a file
z - filter the archive through gzip
  1. x - extract
  2. v - verbose output
  3. j - filter the archive through bzip2
  4. f - read from a file
  5. z - filter the archive through gzip


Hope that helps.
  • AnarchY SI
  • Web Master
  • Web Master
  • User avatar
  • Posts: 2515
  • Loc: /usr/src/MI

Post 3+ Months Ago

tar -zxvf = <3
  • kikwete
  • Novice
  • Novice
  • kikwete
  • Posts: 17

Post 3+ Months Ago

tar is a compression technology used to create a Tape ARchive. The resulting file is known as a tarball.

If you have Window, this is the same as a Zip file. You use winzip to compress and uncompress .zip files.So its the same idea. To uncompress the files (or to get the files out of a tarball), you can use the following commands in linux.

Code: [ Select ]
tar xvf filename.tar


If the tarball has also been gzipped (compressed), you can use the following command:

Code: [ Select ]
tar xvfz filename.tar.gz


If you only want certain directories from the tarball, do this:

Code: [ Select ]
tar xvzf filename.tar.gz */dir.you.want/*


If you have a .tar.bz2 file, then you need bzip2 installed (/usr/ports/archivers/bzip2), and you issue this command:

Code: [ Select ]
tar yxf filename.tar.bz2
  • kc0tma
  • o|||||||o
  • Web Master
  • User avatar
  • Posts: 3316
  • Loc: Trout Creek, MT

Post 3+ Months Ago

kikwete wrote:
If you have Window, this is the same as a Zip file. You use winzip to compress and uncompress .zip files.So its the same idea.


And Windows zipped files are different from tarballs. A zipped file is compressed, whereas a tarball is just a bunch of files clumped together into one unit not at all compressed.

Post Information

  • Total Posts in this topic: 5 posts
  • Users browsing this forum: No registered users and 30 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2015. Ozzu® is a registered trademark of Unmelted, LLC.