Reputation: 2173
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?
Upvotes: 3
Views: 1308
Reputation: 11
I had a bunch of zipped files and I needed to know the uncompressed size, so I came up with the following command:
find foo/*.gz -exec gzip -l '{}' \; |awk '{ sub(/uncompressed/, " "); print } {sum += $2} END {print sum}'
Upvotes: 1
Reputation: 111219
The command
gzip --list filename.gz
will tell you the size of the original uncompressed file, among other things, although not when the original size 4GB or more, like @MarkAdler points out.
Upvotes: 2
Reputation: 112189
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
Upvotes: 3