How to create Md5 hash and verify file in Linux

Mostly it happens when you download an ISO file you see md5 checksum file in the directory of the ISO file but you might not know what is the use of that md5 file. The use of md5 file is to check/verify is your file (assume ISO) downloaded correctly or it is corrupted. In this post I will demonstrate how to verify downloaded file via md5 file and how to create your own md5 files for your files.

In Linux md5sum command is used for all of mentioned task. For instance, if you want to make sure that whether your file has been downloaded correctly or not, you can compare it like below,

$ md5sum -c NameOfYourMd5File

Keep in your mind that your downloaded file should be in the same directory with your md5 file.
Now for generating md5 for your file use the following command.

$ md5sum MyFile.mp3

The output of the command should be something like below,

c22dfc1da3325a3a66b29798956e573 MyFile.mp3

Finally for saving generated md5 in a file easily you should redirect the output of the command to a file like following line.

$ md5sum MyFile.mp3 > MyMd5.md5

If you have more than one file and you want to save all generated md5 in a single file instead of ‘>’ sign use ‘>>’ sign to attach new line to the end of file.

For more information about md5 checksum and md5sum command please refer to following links. Man md5sum command
Wikipedia article about md5sum
Comparison between Md5 and SHA
An academic article about how to implement Md5 algorithm
Another article about Md5 algorithm
An academic article about how to break Md5 and other Hash functions

send your idea and information to

Leave a Reply

Your email address will not be published. Required fields are marked *