What is the difference between md5sum and cksum
Asked Answered
S

1

7

Can someone explain what is the difference between md5sum and cksum, when I compare 2 binary files.

One difference I know is cksum gives the number of "bytes" also along with the checksum value, which md5sum doesn't give.

But my question is to compare 2 binary files, I can chose to use any of these at my will, or they have any specific purposes as well, for specific situations.

Thanks in advance for your help

Stoichiometric answered 29/8, 2013 at 7:45 Comment(0)
R
6

If all you want is to check if 2 specific files are different or not, use cmp FILE1 FILE2. It will stop at the first difference encountered, so you don't lose time calculating checksums for the entire file.

If you do need a full checksum :

  • cksum does a 32 bit ckecksum (CRC-32), while md5sum does a "more reliable" 128 bit checksum.
  • cksum being simpler, it may be faster in some cases, but it may also not be the case because md5sum has been highly optimized for speed.
  • cksum is part of POSIX, and may be present on some systems where md5sum is not.

Note that on Mac OS X, md5sum is not installed by default, but there is md5. The output of md5 -r is in the same format as md5sum.

Redoubtable answered 9/1, 2018 at 14:39 Comment(4)
Mac line breaks are LF, not CR. en.wikipedia.org/wiki/Newline#RepresentationSogdiana
@Alexander: In theory, yes. In practice, it depends on your version of OS X. I see that in High Sierra it is now indeed LF. But in some previous version I had the problem that it was CR.Redoubtable
Yes, Mac OS Classic (pre OS 10), which was like 20 years ago now.Sogdiana
@Alexander: I did mean some (older) version of OS X. (Mac Classic didn't even have a command line). But I can't remember which version gave me this problem.Redoubtable

© 2022 - 2024 — McMap. All rights reserved.