Friday, August 12, 2016

compression - What command do I need to unzip/extract a .tar.gz file?


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?



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


tar -xvzf community_images.tar.gz

Also, to extract in a specific directory


for eg. to extract the archive into a custom my_images directory .


tar -xvzf community_images.tar.gz -C my_images

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.

  • C: means change to directory DIR. In our example, DIR is my_images.


No comments:

Post a Comment

11.10 - Can't boot from USB after installing Ubuntu

I bought a Samsung series 5 notebook and a very strange thing happened: I installed Ubuntu 11.10 from a usb pen drive but when I restarted (...