Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Compression ratio

Tags:

compression

I have a 20Gb tar.gz file containing mainly text and image files compressed. I want to know (without uncompressing the file) how much space it would take on my disk. How can I make an estimation?

like image 943
bigTree Avatar asked Nov 28 '25 18:11

bigTree


1 Answers

In this case, you need to decompress the .gz file. But you don't need to store it or take up all that space on your disk.

Using gzip --list, as suggested in another answer, won't work. The gzip file format stores the uncompressed length in four bytes at the end, so that is only useful for those files that you know some other way for certain has a compressed length of less than 4 GB. In this case, you know for sure that that's not the case, since the compressed size is 20 GB. So the length reported by gzip is useless.

To get the uncompressed length, pipe the output of gzip decompression to something that will count the bytes, like wc. E.g.:

gzip -dc < foo.tar.gz | wc -c
like image 91
Mark Adler Avatar answered Dec 01 '25 15:12

Mark Adler