简体   繁体   English

如何在不提取的情况下获取 zip 中所有文件的 md5sum

[英]How can i get md5sum for all files inside zip without extracting

Is there any way to get md5sum for all/anyone file inside zip without extracting the zip?有没有办法在不提取 zip 的情况下为 zip 中的所有/任何人文件获取 md5sum?

I can extract needed files using unzip <.zip>我可以使用 unzip <.zip> 提取所需的文件

But i need to get md5sum without extracting the zip.但我需要在不提取 zip 的情况下获得 md5sum。

This may not be exactly what you are looking for but it will get you closer.这可能不是您正在寻找的,但它会让您更接近。 You wouldn't be extracting the entire zip but extracting a file to pipe it to md5sum to get checksum.您不会提取整个 zip 而是将文件提取到 pipe 到 md5sum 以获取校验和。 Without reading the contents of the file, md5sum won't be able to generate a hash.如果不读取文件内容,md5sum 将无法生成 hash。

Let's say you have 3 files with this MD5:假设您有 3 个带有此 MD5 的文件:

b1946ac92492d2347c6235b4d2611184  a.txt
591785b794601e212b260e25925636fd  b.txt
6f5902ac237024bdd0c176cb93063dc4  c.txt

You zip them into a single file using zip final.zip a.txt b.txt c.txt你 zip 将它们合并到一个文件中使用zip final.zip a.txt b.txt c.txt

When you list the files, you see there are 3 files.列出文件时,您会看到有 3 个文件。

unzip -l final.zip
Archive:  final.zip
  Length      Date    Time    Name
---------  ---------- -----   ----
        6  2021-08-08 17:20   a.txt
        6  2021-08-08 17:20   b.txt
       12  2021-08-08 17:20   c.txt
---------                     -------
       24                     3 files

To get MD5 of each of the files without extracting the entire zip, you can do this:要在不提取整个 zip 的情况下获取每个文件的 MD5,可以执行以下操作:

unzip -p final.zip a.txt | md5sum
b1946ac92492d2347c6235b4d2611184  -

unzip -p final.zip b.txt | md5sum
591785b794601e212b260e25925636fd  -

unzip -p final.zip c.txt | md5sum
6f5902ac237024bdd0c176cb93063dc4  -

Alternative选择

You can do md5sum *.txt > checksums to get hash of all files and store them in a checksums file.您可以执行md5sum *.txt > checksums以获取所有文件的 hash 并将它们存储在校验和文件中。 Add that to the zip so you know the md5 of each of the file when the files were added to zipped.将其添加到 zip 中,以便在将文件添加到压缩文件时知道每个文件的 md5。

For all files in a zip you can use this;对于 zip 中的所有文件,您可以使用它;

File='final.zip' ; unzip -lqq $File | while read L ; do unzip -p $File ${L##*[[:space:]]} | md5sum | sed "s/-/${L##*[[:space:]]}/" ; done

Gives;给;

b1946ac92492d2347c6235b4d2611184  a.txt
591785b794601e212b260e25925636fd  b.txt
6f5902ac237024bdd0c176cb93063dc4  c.txt

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM