Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

Is it possible to get the size that a tgz will take up once it's extracted, but without extracting it? I basically want

tar tzf file.tgz
with sizes beside them. I'm really looking for a total, so a solution that gives total size but not specific file sizes would work.

share|improve this question

4 Answers 4

up vote 11 down vote accepted

If it compressed using gzip compression, you can do something like:

gunzip -l filename.tar.gz

Since a tar is not compressed, that should give you the information you need.

share|improve this answer
    
Hm, to easy ;) +1 –  Node May 19 '09 at 16:03

Hm I would prefer something like:

tar vtzf somefile.tar.gz |awk '{SUM += $3} END {print SUM}'
share|improve this answer
    
This is the closest to correct. Ideally you would round each $3 up to the filesystem block size. Variations in filesystems make this very difficult to solve in general. At least awk '{SUM+=($3>512?$3:512)}END{print SUM}' - but if you know the filesystem blocksize (if there is one), replace 512 with the actual blocksize. –  carlito May 24 '09 at 0:18
zcat file.tgz | wc -c

Will give you the number of characters taken up by the uncompressed .tar file, which will be very close to correct.

share|improve this answer

You could uncompress the file and then pipe it into wc -c, which will count the number of bytes. Like so:

zcat myfile.tar.gz | wc -c
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.