I have a tar.gz file and I want to extract it using terminal. I used following commands: tar tvzf ldtp_3.5.0.orig.tar.gz and tar -xvzf ldtp_3.5.0.orig.tar.gz. However, I get the same result for both the files:

tar: This does not look like a tar archive
tar: Skipping to next header
tar: Exiting with failure status due to previous errors

I output of the file command shows its a gzip file:

$ file ldtp_3.5.0.orig.tar.gz 
ldtp_3.5.0.orig.tar.gz: gzip compressed data, from Unix

I can extract it using Right-click --> Extract but I want to do that using terminal. Can anyone tell me how to do that?


Looking at the error you are seeing coupled with the fact that you can indeed decompress it says that the file is a genuine TAR/Gzip archive, but perhaps not an immediate TAR is created after the Gzip.

Meaning, if you downloaded this from a web server, sometimes Gzip compression get’s applied to web content on the server level to speed up content download. But if not properly set on the server to ignore already compressed content such as this, it can inadvertently double-Gzip files.

With that in mind I would see if simply un-Gzip it from the command line to see what happens. Use a command like this:

gzip -d ldtp_3.5.0.orig.tar.gz

And see what the resulting file is. I have a funny feeling after you run that command, you will not see a ldtp_3.5.0.orig.tar in the directory but rather a file named like the source—ldtp_3.5.0.orig.tar.gz— but perhaps with modification changed? If that is the case it is truly double-Gzipped. So at this point—after that initial un-Gzip—you can run the tar command you have like this:

tar -xvzf ldtp_3.5.0.orig.tar.gz

And it should now properly decompress the full TAR archive.

Another way of doing something similar to that two step process is to pipe the output of gzip to tar like this:

gzip -dc ldtp_3.5.0.orig.tar.gz | tar -xvzf -

The c in the gzip as well as the - at the end of the command is the key:

  • The c option for gzip will tell gzip to decompress to the standard output stream.
  • The - at the end of the tar command means “use standard input.” So coupled with the the -c in gzip, the pipe will then take the standard output stream piped to it from gzip and connect that to standard input in tar.
  • 1
    I tried the first command gzip -d ldtp_3.5.0.orig.tar.gz and I (oddly) got a .tar file. However, when I tried tar -xvf ldtp_3.5.0.orig.tar I got an error saying: tar: v: Cannot open: No such file or directory tar: Error is not recoverable: exiting now – TheRookierLearner Nov 18 '14 at 19:45
  • @TheRookierLearner Then what happens if you were to do gzip -d ldtp_3.5.0.orig.tar on the ldtp_3.5.0.orig.tar? – Giacomo1968 Nov 18 '14 at 20:07
  • I tried gzip -d ldtp_3.5.0.orig.tar.gz and I got the message gzip: ldtp_3.5.0.orig.tar: unknown suffix -- ignored gzip: on.gz: No such file or directory gzip: the.gz: No such file or directory gzip: ldtp_3.5.0.orig.tar: unknown suffix -- ignored . After this I tried tar -xvzf ldtp_3.5.0.orig.tar and it worked! Thanks a ton! – TheRookierLearner Nov 18 '14 at 21:51

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.