11

I have a lot of files that I need to check. In a UNIX environment I can simply type:

md5sum --check MD5.txt

and the checksum of each file is calculated and compared against the checksums in MD5.txt. How do I do this in a macOS environment. The closest I found was to run

md5 -r * > output.txt

but then I have to manually compare the checksums against the MD5.txt file.

Is there anyway to do this checkup automatically?

2
  • I prefer shasum which does have a -c option for checking. But needs a script to build the check file for all files in a directory tree.
    – Gilby
    Commented Jan 11, 2023 at 22:24
  • 2
    Try md5 -r * | diff -w MD5.txt -.
    – lhf
    Commented Jan 13, 2023 at 11:04

3 Answers 3

9

If you're open to installing Homebrew formulae, rhash and/or md5sum (part of the coreutils package) will do the job:

brew install rhash coreutils

Then:

rhash --md5 --recursive --output=/tmp/md5.txt /path/to/hash

rhash --check --skip-ok /tmp/md5.txt

Or:

find /path/to/hash -type f -exec md5sum {} \; >/tmp/md5.txt 

md5sum --check --quiet /tmp/md5.txt

Omit the --skip-ok or --quiet flags if you want all filenames to be output during verification, otherwise only mismatched ones will be printed.

8

You can use the openssl command (included with MacOS) to create a checksum.

For instance, to create an sha256 checksum:

openssl dgst -sha256 <filename>

To create an md5 checksum:

openssl md5 <filename>

4

You can install this the Microbrew MD5sum/SHA1sum/RIPEMD160sum utility that includes the md5sum tool. It's available with Homebrew:

brew install md5sha1sum

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .