ziulfer
ziulfer

Reputation: 1369

Is it possible to know the space take by files inside a .tar.bz2

I usually use du -h (-h for human readable format) to know the space take by my files. I have compressed some folders with .tar.bz2, but I am not sure if it works well. I mean, if all the files have been properly compressed. I know that it is possible to extract a given file inside the .tar.bz2, but I was wondering if there is a way to du -h inside it.

Upvotes: 0

Views: 195

Answers (2)

wbt11a
wbt11a

Reputation: 818

You could do

tar -jtvf file-name.tar.bz2

If thats not detailed enough, you could use awk to extract the bytes:

tar -jtvf asg2.tar.bz2 | awk '{print $3}'

And if you want to get the total of the bytes, you could do something like:

tar -jtvf asg2.tar.bz2 | awk '{print s+=$3}' | tail -1

And finally, to convert it to human-readable format:

echo $(tar -jtvf asg2.tar.bz2 | awk '{print s+=$3}' | tail -1) | awk '{foo = $1 / 1024 / 1024 ; print foo "MB" }'

Output:

0.00749779MB

Upvotes: 1

A tar.bz2 file is a bzip2-compression of an ordinary tar archive. So it does not contain individually "compressed" files.

You could just list, with tar -tjf foo.tar.bz2, that [decompressed] achive. If that command succeeds, the decompression of the entire foo.tar.bz2 did work.

If you want to compress individual files in an archive, use some other tool, like afio

If you want to measure the total size of the decompressed archive (which is a good overestimate of the cumulated size of all the archived files), try

  bunzip2 < foo.tar.bz2 | wc 

Upvotes: 0

Related Questions