Blog‎ > ‎

Using 7-zip hashing to compare directories and files

posted Dec 21, 2014, 2:17 PM by Sami Lehtinen   [ updated Dec 24, 2014, 9:23 AM ]
You can use 7-zip (7z, 7zip, 7z.exe) to get file hashes easily, by using new h parameter. So 7z h -scrcsha256 produces SHA256 hashes of the files in the directly and subdirectories. That's really easy and secure way to verify that the files are same on recipient and sender. This won't work if you're using too old version, upgrade to latest version. If you don't specify any parameter, CRC32 will be produced, in most of cases that's easier to compare and good enough as it still contains almost 4.3 billion possibilities for different file content. When using UI (7zFM File Manager) you'll find the file hashes under right click menu. 7-zip also supports other hash types like CRC-32 (CRC32), CRC-64 (CRC64), SHA-256 (SHA256) and SHA-1 (SHA1 160 bits) which you can select using the -s parameter on command-line including Linux and Windows versions.

$ 7z h *.txt
7-Zip [64] 9.35 beta  Copyright (c) 1999-2014 Igor Pavlov  2014-12-07

CRC32             Size  Name
-------- -------------  ------------
CDF68C0E         40158  History.txt
FDDB6E75          1927  License.txt
7ED55530          1683  readme.txt
-------- -------------  ------------
4AA74FB3         43768

Files: 3
Size: 43768

CRC32  for data:              4AA74FB3
CRC32  for data and names:    2F50438F

Now it's really easy to see the individual file hashes as well as final hash for data and names. Hash checksum allows really easy comparison of even large directory and file structures including the data content. you can easily verify whole paths over chat, telephone or what ever so nothing hash changed due virus infection, malicious purposes or just old fashioned bit rot aka plain corruption and the stuff you got it's really what it is supposed to be. I know many fellow administrators just use a plain file size to check file content, but that's not a really good way of doing it. Because file content might not be what it seems.

Of course similar results can be achieved using crc32 or sha256sum and using those with tar for complete paths.