When you move files over a network, then there is always the possibility of something going wrong. Even when no error is reported, the file may be corrupt or incomplete. To be sure that everything is correct, you should check the checksum of the file. This can be done with pre-installed tools on nearly every operating system and this article is going to show you how it’s done.
For all the following examples I want to generate a checksum for the file Ataraxis.jar. When you try it on your own, you simply replace Ataraxis.jar with the name of your file.
Windows
CertUtil is a pre-installed tool to work with X509 certificates. However, when you use the option -hashfile
you can generate a checksum for any file you want and not just certificates:
1 2 3 4 |
c:\tmp\AtaraxiS>certutil -hashfile AtaraxiS.jar SHA1 hash of the file AtaraxiS.jar: d9 41 b8 e3 ba 37 d7 68 6e ae bd 36 fb ee ee 5f 51 79 0a b8 CertUtil: -hashfile command completed successfully. |
Without any additional parameter the SHA1 algorithm is used. To change this, you simply add the name of another algorithm (like MD5
or SHA256
) at the end of the command:
1 2 3 4 |
c:\tmp\AtaraxiS>certutil -hashfile AtaraxiS.jar MD5 MD5 hash of the file AtaraxiS.jar: 72 2b 99 91 3e be 15 43 c8 eb 04 9b 0f 70 2e 09 CertUtil: -hashfile command completed successfully. |
Mac OS X
Unfortunately, even on Mac OS X is no graphical tool pre-installed. You therefore need to use the command line as well. The commands are shasum
for the SHA-XXX algorithms and md5
when you need to generate an MD5 checksum:
1 2 3 4 5 6 7 8 |
$ shasum AtaraxiS.jar d941b8e3ba37d7686eaebd36fbeeee5f51790ab8 AtaraxiS.jar $ shasum -a 256 AtaraxiS.jar 9ad9e0abe96c977c4c9c79b91b06d28925a14e44900cfc6815fc08ad6effe57c AtaraxiS.jar $ md5 AtaraxiS.jar MD5 (AtaraxiS.jar) = 722b99913ebe1543c8eb049b0f702e09 |
Linux
On Linux you can use nearly the same tools to generate the checksum of a file. However, to generate a SHA-256 checksum, you can use the dedicated tool sha256sum
:
1 2 3 4 5 6 7 8 |
$ sha1sum AtaraxiS.jar d941b8e3ba37d7686eaebd36fbeeee5f51790ab8 AtaraxiS.jar $ sha256sum AtaraxiS.jar 9ad9e0abe96c977c4c9c79b91b06d28925a14e44900cfc6815fc08ad6effe57c AtaraxiS.jar $ md5sum AtaraxiS.jar 722b99913ebe1543c8eb049b0f702e09 AtaraxiS.jar |
Conclusion
The command-line tools may not be the most user-friendly ones, but they work well and are to your disposal even when you aren’t allowed to install additional software. You never know when they may come in handy.
Thanks for this. I agree the command-line is not comfortable for typical users, but they are definitely time-savers for those in the know. Thanks for the share. Cheers~
—
Sam Smith
Technology Evangelist and Aspiring Chef.
Large file transfers made easy.
http://www.innorix.com/en/DS