[SOLVED] gzip: stdin: not in gzip format

Fix gzip: stdin: not in gzip format error

Hey folks! In this article, we will discuss how to solve gzip: stdin: not in gzip format error while extracting a zipped file using the tar command.

Let’s say you’re trying to extract an archive named archive.tar.gz using the tar command.

tar -xvzf archive.tar.gz

It throws the following error:

Extracting File Shows Error
Extracting File Shows Error

What Could Be the Reason?

First, check the type of the file using the file command, run :

file test archive.tar.gz
Check File type Of The Archive
Check File type Of The Archive

The output says that the given file is a POSIX tar archive, which means the file was not zipped in a tar.gz format, it was only compressed using the tar command and was later renamed for some reason.

The problem arises when you try to extract the compressed file, using a zip (-z) option of the tar command.

Difference between Tar, Zip and Gz

There are a few differences between a tar, a zip, and a gz archive format. Files ending with .tar extension are uncompressed archive files, whereas files ending with .zip extensions are usually compressed zipped files. And a .gz file can or cannot be an archive, but it is a compressed file as well.

Solution for the gzip: stdin: not in gzip format error

 We just have to not use -z attribute in our tar command to begin the extraction of the archive. Type the following commands in your terminal and run :

tar -xf archive.tar.gz

Now, your file will be extracted correctly, as this time we do not encounter any error on our screen.

No Error During Extraction Using xf Option
No Error During Extraction Using xf Option

Conclusion

Because naming conventions do not matter in Linux, one can get easily confused if someone decides to rename a video file in .txt format. It will still play, mind you, but it will be confusing to a lot of new users. Similarly, if someone renames a .tar file to .tar.gz extension, it will cause problems as well. Use file command followed by the name of the file to know the format of any file if you encounter any issue while executing it. We hope you solved your encountered problem with the help of this article.