Go2Linux | Linux Operating System

A site dedicated to: Linux Operating System

Verify the integrity of files using md5

Date: 2009-03-24 00:00:00 -0400

This week I had to move a big .tar.gz file from an ftp server to another one, and I had to bring it first to my PC before sending it to the other server, and when I uploaded there it has errors, the same error it has in my Desktop, so I could have avoided the waste of time of sending it to the second server if I could have checked its integrity when it has arrived to my Desktop.

Well the second time I did that and this time was all OK, here is how to check the integrity of files

First creat an MD5 file of the file to move.

md5sum file > file.md5.txt

You will have to take both files with you, or move them anyway you can or prefer, once in its final destination, you can check the md5 again.

md5sum -c file.md5.txt

Now if you want to make it recursively into directory, you may use this.

find . -name ‘*’ -exec md5sum {} >file.md5.txt \;

This will create a file of two columns like this:

bce4769e984bcb13961eb7a149038c50  ./xp15.png
b9a474939619ce6717fc87b1d5873f7d  ./office6.png
e3e202d0be6e4bd4b449537c0819b851  ./xp10.png
19eb11c9a24fd08b194f5a494f5fdebe  ./office1.png
5f298a05a16e20367ac8b35054e6883d  ./xp16.png
63ffe1ad007e03f8f453eea82c43e21d  ./office7.png
c02828d6aefd4933cc301049bd0ea96a  ./office4.png
27018941f05a1ac35181f6ac65fe20c2  ./ubuntu9.png
712a0b02dce62150abe951695dfc1045  ./vista12.png
d0d67fba12d931353602d6272756a127  ./office5.png
a3c37a6459fd2d878cd79dbefcbb01cd  ./ubuntu7.png
462476e1871a7f8d2685d999e9fa6ce8  ./xp2.png
7896b477aaa2d78624954adf7664d806  ./office3.png
f9f82d3de48bacef46daa263334c30a9  ./xp20.png
4a1a3f9b8d28658d7c6943e72280fd6a  ./ubuntu1.png
0a9e024cb0832600b5dad95a56ee8726  ./ubuntu5.png
27ef5890cf81f190839f78f93b3d4117  ./xp13.png
d7534122e4f2277369f69cb0720f817e  ./vista10.png
e19b7b08f3e16ce555a9fa3a44f07721  ./vista14.png

And to check if all is OK run this

md5sum -c file.md5.txt

The first command is finding all files in this directory, and then run md5sum on each of the found files, then stores the output to the file.

If you liked this article please share it.

powered by TinyLetter

If you want to contact me in any other way, please use the contact page.