检查tar gz文件的总内容大小 [英] Check the total content size of a tar gz file

查看:281
本文介绍了检查tar gz文件的总内容大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何从命令行提取.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)列出存档中的文件. sedcut隔离文件大小字段.第二个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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆