Linux Commands

How to solve gzip: stdin: not in gzip format error

While working with the archived files in Linux, we might face the error “gzip:stdin: not in gzip format”. This error occurs because the file has only been archived, not compressed. That means the file is not compressed using gzip utility rather renamed. Before learning how to fix this issue, first, we will try to understand the gzip files. The gzip is the abbreviation of GNU zip and is used to compress, decompress the files.

This write-up guides how to solve “gzip:stdin: not in gzip format” in Linux and we will also explain the root cause of this error.

How to fix gzip: stdin: not in gzip format in Linux

We have a file in our system with the name “myfile.tar.gz”, we will try to extract the file using the command:

$ tar xvzf myfile.tar.gz

The error will be generated, which means the file is not in the gzip format. To know the format of file, we will use the file command:

$ file myfile.tar.gz

The file, myfile.tar.gz is in the POSIX tar archive (GNU) format instead of the gzip format. It means that the file has only been archived and not compressed using gzip. The name of a file has been changed by adding the “.gz” extension. Now as we know this file is only archived and not compressed, we can extract the file removing the “z” flag as this flag is used for gzipped files only.

$ tar xvf myfile.tar.gz

We have another file with the name of “myzipfile.tar.gz” which is compressed using gzip utility. We will try to extract the file using the command:

$ tar xvzf myzipfile.tar.gz

The file has generated no error because the file is compressed using the gzip utility instead of adding the extension.

Conclusion

The error “gzip: stdin: not in gzip format” occurs when the file is not in the gzip format. There are two cases; either the file is only archived and renamed with the “.gz” extension or the file is in some other format. The gzip is used to zip, compress, or decompress the files. In this write-up, we have discussed the “gzip: stdin: not in gzip format” error and explained with examples why this error occurs and how it can be solved.

About the author

Hammad Zahid

I'm an Engineering graduate and my passion for IT has brought me to Linux. Now here I'm learning and sharing my knowledge with the world.