can't decompress .tgz using gunzip

8,001

Solution 1

The command you're showing in your first line (tar -cvfz example2.tgz example1) doesn't work and it should not output any file example2.tgz. Didn't you get an error? Perhaps the file example2.tgz existed already? Check if you have a file called z in that folder - that's where the tgz has been saved to, because:

The -f parameter specifies the file which must follow immediately afterwards: -f <file>

Try

tar cvzf exam.tgz example1

Solution 2

just to precise, creation

tar cvzf example2.tgz example1

extraction

tar xvzf example2.tgz

where

  • c : create
  • x : extract
  • v : verbose
  • z : compress
  • f : target tar/tar gz file argument, sould be placed last

the trick is that f is expecting a file, which should be next.

Share:
8,001
user53029
Author by

user53029

Updated on September 18, 2022

Comments

  • user53029
    user53029 over 1 year

    I was able to archive and compress a folder with the following command:

    tar -cvfz example2.tgz example1
    

    I then removed the example1 folder and tried to unpack the archive using this command:

    tar -xvfz example2.tgz 
    

    and tried

    tar -zxvf example2.tgz 
    

    Niether of these commands worked. The error returned was:

    gzip: example2.tgz: not in gzip format
    tar: This does not look like a tar archive
    tar: Exiting with failure status due to previous errors
    

    It clearly used gzip compression since I passed tar the z qualifier in the initial command. What am I doing wrong? I am on Ubuntu 14.0.4

  • user53029
    user53029 over 9 years
    No, on initial creation I did not get any errors and the example2.tgz file was placed into my home directory. I did not already have a file with that name. What is max.dat and what does it do?
  • user53029
    user53029 over 9 years
    well that just went away that's strange
  • Sebastian
    Sebastian over 9 years
    that was a unintential copy paste error on my side, it's corrected already.
  • Sebastian
    Sebastian over 9 years
    can you confirm you have a file z in your folder?
  • user53029
    user53029 over 9 years
    I did have some z files in there. They only showed up after I ran the extraction command with subsequent failures. However, after following your instructions and placing the "f" param last in the sequence, I can now unzip the .tgz file. Thanks for the help Sebastian :)
  • user53029
    user53029 over 9 years
    yeah, my Linux study guides fail to mention that small but crucial detail lol
  • Gilles 'SO- stop being evil'
    Gilles 'SO- stop being evil' over 9 years
    Just to make things more confusing, in order to be compatible with historical implementations, GNU tar and IIRC a few others parse tar cvfz exam.tgz example1 as creating a compressed archive exam.tgz, but tar -cvfz exam.tgz example1 creates a plain tar archive z containing exam.tgz and example1. The reason is that the original tar implementation didn't use what has now become the standard for command line switches, and instead used its first argument as a block of switches.