Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I have a file.tar.bz2 that's about 50GB and would like to extract it however I don't know how much space I will need. Is there a command to print the compression ratio of the tar.bz2 file?

share|improve this question

migrated from stackoverflow.com Nov 3 '12 at 0:48

This question came from our site for professional and enthusiast programmers.

add comment

3 Answers

up vote 3 down vote accepted

I don't know of a command specifically for printing out compression ratios, but

bzip2 -dc file.tar.bz2 | wc -c

should show you the number of bytes taken up by the uncompressed tar file. Some of that space is taken up by the tar metadata, but it should give you a ballpark estimate.

share|improve this answer
add comment
tar -tvjf file.tar.bz2

Will list all the files in the tar file, their respective sizes, and other information. You could always pipe the output through an awk script to add up the numbers...

tar -tvjf file.tar.bz2 | awk '{i+=$3;print i"     "$0}' | tail
share|improve this answer
1  
or tar -tvjf file.tar.bz2 | awk '{i+=$3} END{print i}' - will only print the sum of all sizes –  mata Nov 2 '12 at 22:19
add comment

Seeing as this is where search brought me for doing the same thing with .tar.gz files, so I'll add that

tar -tvf file.tar.gz | awk '{i+=$3} END{print i}'

will work for those. ie just leave out the j that specifies bz2 format. I would of posted this as a comment @TooLazyToLogIn's post but I don't have the rep for that.

share|improve this answer
add comment

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.