Skip to content

Solved: extract, creat and etc. tar.gz

Solved: extract, creat and etc. tar:

  1. reshenie:

48 down vote accepted

You can make a tar archive of the source, copy that to the other computer using the USB drive, and extract it there. Tar preserves file permissions.

1 - On the source computer:

cd /path/to/folder/to/copy tar cvpzf put_your_name_here.tar.gz .

2 - Copy put_your_name_here.tar.gz to the USB drive and then to the other computer

3 - On the destination computer:

cd /path/to/destination/folder tar xpvzf put_your_name_here.tar.gz

tar will recreate the archived folder structure with all permissions intact.

Those commands will archive the contents of the source folder and then extract them into the destination folder. If you want to copy the folder itself, then you should, at step 1:

cd /path/to/parent/folder tar cvpzf put_your_name_here.tar.gz folder_to_copy

The same mechanism could be used for single files.

https://askubuntu.com/questions/225865/copy-files-without-losing-file-folder-permissions

  1. reshenie:

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? extract unzip shareimprove this question

edited Dec 31 '13 at 23:46 Braiam 47k17122195

asked Feb 8 '11 at 22:50 EmmyS 4,315112945

add a comment 4 Answers active oldest votes up vote 840 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.

shareimprove this answer

edited Mar 9 '17 at 2:35

answered Feb 8 '11 at 22:57 djeikyb 17.1k74481

3

@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 2

This is one of the better explanations out of the millions of similarly phrased questions – JohnMerlino Oct 5 '14 at 14:48

On Android Marshmallow this does not work and gives u0_a83@flounder:/ $ tar -xvzf /sdcard/Download/ubuntu* tar: exec gunzip: No such file or directory tar: read error – Suici Doga Mar 6 '16 at 6:38

My file is a tar.gz file.So do I have to root and install GNU ZIP – Suici Doga Mar 6 '16 at 11:26

@SuiciDoga oh, i misread, sorry. yes, you'll need to install the gunzip program – djeikyb Mar 6 '16 at 20:01 show 8 more comments up vote 104 down vote

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

enter image description here

Note: Make sure you make the directory first (mkdir ~/Pictures/Community). shareimprove this answer

edited Oct 29 '14 at 9:55

answered Aug 20 '14 at 11:02 JorgeArtware 2,04711418

4

don't forget C for "change directory"! also, i feel it's better not to mix hyphen and non-hyphen options (especially confusing when using ps). – djeikyb Nov 5 '14 at 23:45 1

Why is it not -o like every other command ever? – Jan M. Mar 1 '17 at 13:57

I love your hint 'tar to e X tract a F ile' – Nam G VU Nov 13 '17 at 7:11 add a comment up vote 78 down vote

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). shareimprove this answer

answered Dec 31 '13 at 23:54 djeikyb 17.1k74481

1

Is there any documentation on this? I've been searching all over for a reference to this, I never use the -z flag and everything gets gzipped so I've been worried if I haven't been compressing my tarballs at all, haha. Thanks. – neurosnap Jul 10 '15 at 4:14 2

@neurosnap see the gnu manual and of the bsd's manual – djeikyb Jul 12 '15 at 20:49 3

Probably would have been better to edit your original answer. – Seth Jun 9 '16 at 18:04 2

@Seth it feels/felt distinct enough to be a separate answer, especially in context of the destructive edit that provoked it. I'll rethink it after work though, might be a simpler way to merge than I originally thought. – djeikyb Jun 9 '16 at 18:23 1

@EnricoMariaDeAngelis bsd tar since at least 2004 and gnu tar since at least 2010 have supported auto-selecting a decompressor. it's possible no "recent" (this century? nineties+?) version of tar requires manually selecting a decompressor. – djeikyb Jun 2 '17 at 4:39 show 2 more comments up vote 1 down vote

In case you are not able to extract .tar.gz file using

tar -xvzf fileName.tar.gz

Try extracting using

tar xf fileName.tar.gz

shareimprove this answer

answered Jan 5 '17 at 6:29 Shravan40 1741213

2

if it is a gzipped tar file, the first command will always work. if it does not work, you do not have a gzipped tar file. the latter command is a great recommendation for folks who don't care what compression algorithm was used on their tar file. – djeikyb Mar 9 '17 at 2:37 add a comment

https://askubuntu.com/questions/25347/what-command-do-i-need-to-unzip-extract-a-tar-gz-file