With the commands md5sum, sha1sum, sha256sum I can take a text file having an hash and a path per line and verify the entire list of files in a single command, like sha1sum -c mydir.txt. (Said text file is easy to produce with a loop in find or other.)

Is there a way to do the same with a list of CRC/CRC32 hashes?

Such hashes are often stored inside zip-like archives, like ZIP itself or 7z. For instance:

$ unzip -v archive.zip 
Archive:  archive.zip
 Length   Method    Size  Cmpr    Date    Time   CRC-32   Name
--------  ------  ------- ---- ---------- ----- --------  ----
 8617812  Stored  8617812   0% 12-03-2015 15:20 13fda20b  0001.tif


$ 7z l -slt archive.7z

Path = filename
Size = 8548096
Packed Size =
Modified = 2015-12-03 14:20:20
Attributes = A_ -rw-r--r--
CRC = B2F761E3
Encrypted = -
Method = LZMA2:24
Block = 0
  • Yes, I'm aware of askubuntu.com/q/303662/395065 – Nemo Dec 18 '15 at 13:00
  • It's unlikely that there'll be a command to verify CRC hashes recursively. What would be more usual is for two or more commands to be combined to deliver the target requirement. There'll be answers to "How do I run a command recursively", and "How do I extract a particular value from a list", I'm sure. – roaima Dec 18 '15 at 13:43
  • Sure, but that's not the question. Here we are looking at a specific feature of the various hashing options. 7z h is a recent example of tool for recursive hashing in CRC32 and more. – Nemo Dec 20 '15 at 9:18

The crc32 utility does not have an option like -c of the sha1sum. Nevertheless the verification can be done in a script.

Let say we have stored crc32 values in file in the same format like sha1sum prints values:

a8374911 *file1.ext
32c5188e *file2
6592d5e5 *bflmpsvz

The crc32 can be checked via bash script:

while read line
   name=${line#* \*}
   crc32=`crc32 "$name"`
   echo -n "$name: "
   if [ "${line% \**}" == "$crc32" ]
      echo OK
      echo FAILED
done < file_with_crc32

The script provides the same output as sha1sum -c. It iterates over all lines in the file file_with_crc32 and for each line

  • retrieves the filename from read line
  • calculates crc32
  • compares the calculated value with the value from file
  • prints the result

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.