I was a bit surprised to learn that my Mac didn’t have the md5sum and sha1sum tools installed by default. A quick search and I found a site that provides the source. The sources compiled successfully on my Mac (OS X 10.5.5, xCode tools installed).
The only quirk appears in the last step:
$ ./configure
$ make
$ sudo make install
cp md5sum sha1sum ripemd160sum /usr/local/bin
chown bin:bin /usr/local/bin/md5sum /usr/local/bin/sha1sum \
/usr/local/bin/ripemd160sum
chown: bin: Invalid argument
make: *** [install] Error 1
The make install command tries to change the ownership of the files to the bin user. Since that user doesn’t exist on my system, the command fails. This isn’t a problem though, as both binaries work perfectly. By default, they are installed to /usr/local/bin/.
Update
As a commenter pointed out, the /sbin/md5 utility provided by OS X contains a hidden -r switch that causes it to output in a format identical to that of md5sum, making it compatible with scripts that require md5sum’s format. If you want to use the md5 utility provided by OS X, you can add the following to your ~/.profile or ~/.bashrc:
alias md5='md5 -r' alias md5sum='md5 -r'


Thanks,
Worked perfectly. Why would they take md5sum out of 10.5 from 10.4 ?
Yeah, I have no idea why they would remove them from 10.5. Seems kinda silly since they are very basic and lightweight Unix tools.
seems they only include md5, which may have a slightly different output to md5sum, but from what I gather, does the same thing..? still, they could have made md5sum symlink to md5
Hey Nevyn,
You’re absolutely correct! OS X includes /sbin/md5, however it’s output is different than the md5sum utility:
$ md5 myfile.iso
MD5 (myfile.iso) = 3d763a372e34681287712f661ecb598c
$ md5sum myfile.iso
3d763a372e34681287712f661ecb598c myfile.iso
Many scripts that utilize the md5sum utility expect the output to be in a particular format. If the format is different (as it is with the md5 command), it will break the scripts that use it.
I had same problem, however, after a while of googling, I found that md5 has hidden switch -r
$md5 myfile.txt
MD5 (myfile.txt) = 2930560673edb5b823e0818265737914
$md5 -r myfile.txt
2930560673edb5b823e0818265737914 myfile.txt
Wow, that’s awesome! Thanks Arnost!
I haven't found an md5sum that wasn't exactly as calculated using md5 on the Mac. (OSX 10.4.11).
For sha1sum you can do "openssl sha1 <path/filename.ext>".
Hey Nuke,
Were you able to compile the md5sum from scratch like I explained in the post?
Won’t quite do the same since it won’t actually accept a source file to check sha1 sums against, but if you just need to generate compatible output, you could try defining the following function in your .bashrc:
sha1sum ()
{
openssl sha1 $1 | sed ‘s/.*(\(.*\))= \(.*\)$/\2 \1/’
}
This will, on a “sha1sum foo.txt” generate the expected output…
Thanks for the tip, Eugene!
Eugene’s trick works with md5 as well.
md5sum ()
{
md5 -r $1
}
Thanks for the tip, Travis! I actually rewrote about this problem on my tech blog and used a similar solution:
http://solidstateraam.com/mac-os-x-replicating-md5sum-output-format/
Wow why did they not include a compatible version? Anyway you hint worked a champ.
Thanks!
-roger-
I would recommend installing homebrew and running ‘brew install coreutils’.
http://mxcl.github.com/homebrew
Thanks for the tip, Richard! :)
$openssl md5 yourfile
Thank you for the tip, Antony! :)