检查 tar gz 文件的总内容大小
如何从命令行提取 .tar.gz 文件中未压缩文件数据的总大小?
How can I extract the size of the total uncompressed file data in a .tar.gz file from command line?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
这适用于任何文件大小:
对于小于 4Gb 的文件,您还可以将 -l 选项与 gzip 一起使用:
This works for any file size:
For files smaller than 4Gb you could also use the -l option with gzip:
这将总结提取的文件的总内容大小:
输出以字节为单位。
说明:
tar tzvf
以详细格式(如ls -l
)列出存档中的文件。sed
和cut
隔离文件大小字段。第二个sed
在除第一个之外的每个大小前面放置一个 +,然后paste
将它们连接起来,给出一个和表达式,然后由bc
计算该表达式。请注意,这不包括元数据,因此当您提取文件时,文件占用的磁盘空间将会更大 - 如果您有很多非常小的文件,则可能会大很多倍。
This will sum the total content size of the extracted files:
The output is given in bytes.
Explanation:
tar tzvf
lists the files in the archive in verbose format likels -l
.sed
andcut
isolate the file size field. The secondsed
puts a + in front of every size except the first andpaste
concatenates them, giving a sum expression that is then evaluated bybc
.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.
对于大于 2Gb 的文件大小,命令
gzip -l archive.tar.gz
无法正常工作。我会推荐zcat archive.tar.gz | wc --bytes 而不是非常大的文件。The command
gzip -l archive.tar.gz
doesn't work correctly with file sizes greater than 2Gb. I would recommendzcat archive.tar.gz | wc --bytes
instead for really large files.我知道这是一个古老的答案;但两年前我专门为此编写了一个工具。它称为
gzsize
,它为您提供 gzip 的未压缩大小' ed 文件而不实际解压缩磁盘上的整个文件:I know this is an old answer; but I wrote a tool just for this two years ago. It’s called
gzsize
and it gives you the uncompressed size of a gzip'ed file without actually decompressing the whole file on disk:使用以下命令:
Use the following command:
我在网络上找到了所有网站,但当文件大小大于 4GB 时,无法解决获取大小的问题。
首先,哪个最快?
当然,tar -xvf 是最快的,但是
¿如何在获取标头后取消执行?
我的解决方案是这样的:
I'm finding everything sites in the web, and don't resolve this problem the get size when file size is bigger of 4GB.
first, which is most faster?
definitely, tar -xvf is the most faster, but
¿how to cancel executions after get header?
my solution is this:
tar 文件被解压缩,直到/除非通过其他程序过滤,例如 gzip、bzip2、lzip、compress、lzma 等。tar 文件的文件大小与解压缩的文件相同,可能小于 1kb添加标头信息以使其成为有效的 tarball。
A tar file is uncompressed until/unless it is filtered through another program, such as gzip, bzip2, lzip, compress, lzma, etc. The file size of the tar file is the same as the extracted files, with probably less than 1kb of header info added in to make it a valid tarball.