File Check with MD5 Hash Using Linux

There are many times that you need to be sure that a file you downloaded from the internet or copied from a location is the same as the original.

There are many tools that can help you with that but my favorite is md5sum (and md5deep when it comes to comparing directories).

The usage is very simple. The command md5sum FILE will show you the hash for the file and the file name. So the only thing you have to do is get the sum of the original file, the sum of your file and compare them. If they are the same, your file is not corrupted or tampered with.

Comparing the hashes your self may not be very easy but there is a way to do it using a hash file. Simply save the result of the above command to a file, like md5sum FILE > hashfile.md5 and then use the option -c to compare the hash of your file to the hash in the hashfile.

I always use relative paths because that way you can export the hash of the file to a hash file that is on the same directory with the original file for example, copy the hash file to the directory where the new file is saved and then execute the command md5hash -c.

The same thing can be done for all files in a directory tree using md5deep to produce the hash file and then md5sum to compare the files. You have to use the argument -rl with md5deep in order to get all files (r) and use relative paths (l) so you can compare the files later.

There are many other ways to get the hashes of all files in directory trees, like using the command find, pipe it to xargs and then md5sum but I'd rather use md5deep unless you do not want to check all the files in the directory tree.

Popular posts from this blog

Syslog Message Collection for OMS from sources that do not support the agent

How to Configure Message Forwarding on a Mailbox Level

IIS Client Certificate Revocation Check Disable