检查tar gz文件的总内容大小 [英] Check the total content size of a tar gz file
问题描述
如何从命令行提取.tar.gz文件中未压缩的文件数据的总大小?
How can I extract the size of the total uncompressed file data in a .tar.gz file from command line?
推荐答案
这将对提取的文件的总内容大小求和:
This will sum the total content size of the extracted files:
$ tar tzvf archive.tar.gz | sed 's/ \+/ /g' | cut -f3 -d' ' | sed '2,$s/^/+ /' | paste -sd' ' | bc
输出以字节为单位.
说明:tar tzvf
以冗长的格式(如ls -l
)列出存档中的文件. sed
和cut
隔离文件大小字段.第二个sed
在每个大小前面都加上一个+,第一个paste
则将它们连接起来,给出一个求和表达式,然后由bc
对其求值.
Explanation: tar tzvf
lists the files in the archive in verbose format like ls -l
. sed
and cut
isolate the file size field. The second sed
puts a + in front of every size except the first and paste
concatenates them, giving a sum expression that is then evaluated by bc
.
请注意,这不包括元数据,因此,文件在提取文件时所占用的磁盘空间将会更大-如果文件很多,则可能要大很多倍.
Note that this doesn't include metadata, so the disk space taken up by the files when you extract them is going to be larger - potentially many times larger if you have a lot of very small files.
这篇关于检查tar gz文件的总内容大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!