0

我通常使用du -h(-h 表示人类可读格式)来了解我的文件占用的空间。我已经用 压缩了一些文件夹.tar.bz2,但我不确定它是否运行良好。我的意思是,如果所有文件都已正确压缩。我知道可以在其中提取给定文件.tar.bz2,但我想知道是否有办法du -h进入其中。

4

2 回答 2

1

你可以做

tar -jtvf file-name.tar.bz2

如果这还不够详细,您可以使用 awk 来提取字节:

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

如果您想获取字节总数,您可以执行以下操作:

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

最后,将其转换为人类可读的格式:

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

输出:

0.00749779MB
于 2014-06-20T13:24:49.583 回答
0

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 
于 2014-06-20T08:37:31.370 回答