Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I received a huge .tar.gz file from a client that contains about 800 mb of image files (when uncompressed.) Our hosting company's ftp is seriously slow, so extracting all the files locally and sending them up via ftp isn't practical. I was able to ftp the .tar.gz file to our hosting site, but when I ssh into my directory and try using unzip, it gives me this error:

[esthers@clients locations]$ unzip community_images.tar.gz
Archive:  community_images.tar.gz
  End-of-central-directory signature not found.  Either this file is not a zipfile, or it constitutes one disk of a multi-part archive.  In the latter case the central directory and zipfile comment will be found on the last disk(s) of this archive.
note:  community_images.tar.gz may be a plain executable, not an archive
unzip:  cannot find zipfile directory in one of community_images.tar.gz or community_images.tar.gz.zip, and cannot find community_images.tar.gz.ZIP, period.

What command do I need to use to extract all the files in a .tar.gz file?

share|improve this question

3 Answers 3

up vote 101 down vote accepted

Type man tar for more information, but this command should do the trick:

tar -xvzf community_images.tar.gz

To explain a little further, tar collected all the files into one package, community_images.tar. The gzip program applied compression, hence the gz extension. So the command does a couple things.

  • f: this must be the last flag of the command, and the tar file must be immediately after. It tells tar the name and path of the compressed file.
  • z: tells tar to decompress the archive using gzip
  • x: tar can collect files or extract them. x does the latter.
  • v: makes tar talk a lot. Verbose output shows you all the files being extracted.
share|improve this answer
    
Thanks! That's what I needed. –  EmmyS Feb 8 '11 at 23:00
1  
@Shiki I saw your proposed edit. I don't think it's an appropriate change, I prefer the way I explained this tool. I do think your tar -xf suggestion would make a great additional answer. –  djeikyb Dec 2 '13 at 18:05
    
This is one of the better explanations out of the millions of similarly phrased questions –  JohnMerlino Oct 5 at 14:48

At some point tar was upgraded to auto-decompress. All you need now is:

tar xf community_images.tar.gz

The same explanation applies:

  • f: this must be the last flag of the command, and the tar file must be immediately after. It tells tar the name and path of the compressed file.
  • x: extract the files.

Note the lack of hyphen for the command flags. This is because most versions of tar allow both gnu and bsd style options (simplistically, gnu requires a hyphen, bsd doesn't).

share|improve this answer

If you want the files to be extracted to a particular destination you can add -C /destination/path/

Example:

tar xf community_images.tar.gz -C /home/emmys/Pictures/Community/

You can easily memorize it if you consider telling tar to e X tract a F ile

share|improve this answer
    
Thanks, it helped me solve this problem –  Brady Zhu Oct 9 at 10:05

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.