4

What is a nice command-line trick to tell if a .gz file is really gzipped, as opposed to being a non-Gzip file just named that way?

9

You can use the file command to do this. It will look at the magic numbers in the file and tell you what type it really is.

  • 1
    Although it works I feel like there should be a better way. – 7hi4g0 May 21 '14 at 15:10
7

If it is gzip'd the first two bytes are 0x1F and 0x8B.

To get more complicated than that you will need to understand the file format. See here: http://www.gzip.org/zlib/rfc-gzip.html and go down to "Member header and trailer" section where you can identify a gzip by its 10 byte header.

  • Interesting info. But it feels like something that were supposed to be on the program with a verify option or something like that. – 7hi4g0 May 21 '14 at 15:11

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.