Is there a command to determine the compression ratio of a tar.bz2 file?

13,050

Solution 1

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.

Solution 2

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:
13,050
user784637
Author by

user784637

Updated on September 18, 2022

Comments

  • user784637
    user784637 over 1 year

    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?