The md5sum program is used to calculate and verify 128-bit MD5 hashes. This program is installed by default in most Unix, Linux, and Unix-like operating systems including BSD. Mac OS X is a BSD variant and it also includes the md5sum program. However, the program is called md5 instead of md5sum and outputs an MD5 checksum in a different format than the standard md5sum program.
Here's what the standard md5sum output looks like:
$ md5sum test.txt
d0ea20794ab78114230ba1ab167a22c2 test.txt
Now here's what the output of md5 on Mac OS X looks like:
$ md5 test.txt
MD5 (test.txt) = d0ea20794ab78114230ba1ab167a22c2
While this normally wouldn't be a big deal, it can cause major issues if you're trying to run scripts that were written for a Unix-like environment which expect the default md5sum format.
Thankfully, md5 has a switch that reverses the output:
$ md5 -r test.txt
d0ea20794ab78114230ba1ab167a22c2 test.txt
If you'd like to permanently change md5's behavior to mimic that of md5sum, you have two options:
The first is to simply add the following alias to ~/.profile
:
alias md5sum='md5 -r'
Now when you type 'md5sum test.txt
', the command will be replaced with 'md5 -r test.txt
'. However, this may not work with your scripts.
The second solution, and my preferred method, is to create a small script called md5sum
that contains the following:
#!/bin/bash
/sbin/md5 -r "$@"
I then make this script executable (chmod +x md5sum
) and put it in /sbin/
. Now, whenever a script calls md5sum, the small bash script above is used and it produces output identical to that of md5sum on other Unix systems.