Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Please find my OS details:

$ uname -a
AIX xxyy 1 6 000145364C00

I've tried the following command to get size of a file in gzip archive:

$ gzip -l mycontent.DAT.Gz
compressed  uncompr.   ratio   uncompressed_name
-1223644243 1751372002 -75.3%  mycontent.DAT.Gz

Not sure how to interpret the unzipped size from this. Compressed file size close to 4 GB.

So, I tried this option in order to capture correct data:

$ zcat mycontent.DAT.Gz | wc -c

It gives me this error:

mycontent.DAT.Gz.Z:A file or directory in the path name does not exist.

Can you please tell me how to capture this value from shell script without decompressing the source file?

share|improve this question
Are you sure about the integrity of the archive? It reports its own compressed size as ~1.7G. If it is really ~4GB I would guess there is a problem. – terdon Jul 14 '13 at 14:41

To answer the question title:

How can I get the uncompressed size of gzip file without actually decompressing it?

As you obviously know, the option -l (--list) is usually showing the uncompressed size.
What it shows is not calculated from the data, but was stored in the header as part of the compressed file.

In your case, the -l option does not work for some reason.
But it's not possible to 'measure' the uncompressed size from the raw compressed data - there is just no information about anything else in the compressed data - which is not surprising, as the point of compression is to leave out anything not needed.

You do not need to store the uncompressed data on the disk: zcat file.gz | wc -c is the right approach - but as @OleTange answered, your zcat seems to be not the one from gzip.
The alternative is using the gzip options -d (--decompress) and -c (--to-stdout), combined with wc option -c (--bytes):

gzip -dc file.gz | wc -c
share|improve this answer
The -l option has a bug for files bigger than 4GB: – Flimm Jun 29 '15 at 11:29

You zcat is not GNU zcat but from compress. Try:

gzcat mycontent.DAT.Gz | wc -c
gzip -dc mycontent.DAT.Gz | wc -c
share|improve this answer
This decompresses the source file. Maybe it's what the OP wants, but this is not the answer to the question. – Marco Jul 14 '13 at 16:54
Ah, that explains why it was looking for a file ending in .Z – Hennes Sep 29 '15 at 16:38

gzip -l did not work for me, just git -1 ... but this did:

unzip -l
share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .