linuxshellunixshmd5sum

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?

I can extract needed files using unzip <.zip>

But i need to get md5sum without extracting the zip.


Solution

  • 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. Without reading the contents of the file, md5sum won't be able to generate a hash.

    Let's say you have 3 files with this 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

    When you list the files, you see there are 3 files.

    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:

    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. Add that to the zip so you know the md5 of each of the file when the files were added to zipped.