9

To illustrate the point: I have downloaded the LEDA library from the company's website. Using tar -xzf on it fails:

$ tar -xzf LEDA-6.3-free-fedora-core-8-64-g++-4.1.2-mt.tar.gz 
tar: This does not look like a tar archive
tar: Skipping to next header
tar: Exiting with failure status due to previous errors

However, gunzip followed by tar -xf works just fine:

$ gunzip LEDA-6.3-free-fedora-core-8-64-g++-4.1.2-mt.tar.gz
$ tar -xf LEDA-6.3-free-fedora-core-8-64-g++-4.1.2-mt.tar
# no error

Can anyone tell me why this could be?- I'd want the standard tar command to work all the time.

  • What operating system? IIRC there are Unixes with a tar that does not implement -z – Bananguin Apr 15 '13 at 19:05
  • @user1129682 From the company's site, it looks like it only has options for Linux and Win... – MattDMo Apr 15 '13 at 19:07
  • If your tar does not support z, use a pipe instead: gunzip < archive.tar.gz | tar -x should work everywhere. – frostschutz Apr 15 '13 at 19:07
  • If your copy of tar does not support gunzip decompression, you can do the following instead: gunzip -c $file | tar -x. It's common to wrap that up in a shell function. – user26112 Apr 15 '13 at 19:08
  • 1
    I just downloaded that archive, and indeed tar xzf gives an error, on Debian GNU/Linux (which of course uses gnutar). Odd. – derobert Apr 15 '13 at 19:29
12

What appears to have happened is that they've double compressed the archive.

If you run file on your gunzip'd file, you'll find its still a gzip archive. And if you rename it to have .gz again, you can gunzip it again.

It seems recently gnu tar will automatically add the -z option, provided the input is a file. So, that's why it works without the -z option after you'd already run gunzip once, tar automatically added it.

This behavior is documented, from the info page:

"Reading compressed archive is even simpler: you don't need to specify any additional options as GNU `tar' recognizes its format automatically. [...] The format recognition algorithm is based on "signatures", a special byte sequences in the beginning of file, that are specific for certain compression formats."

That's from §8.1.1 "Creating and Reading Compressed Archives."

| improve this answer | |
  • Very well spotted! Confirmed with all combinations of gunzip and tar. – Michael Schubert Apr 15 '13 at 20:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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