Friday, December 12, 2008

Verifying downloaded files

diff is a Linux command that will compare the contents of two files. At first you may not be able to appreciate its presence in Linux distros but it is one of the important Linux programs.

Consider the scenario when you are downloading something and the web site says it has a hash value (i.e, sha1sum, md5). This hash value will be used to verify whether the file you downloaded is OK (i.e., not corrupted.) If you are new to this stuff, you may wondering how in the world can I use such information for verification. Here's how.

After the download you need to compute for the hash value of the file. You can do it using:

for Fedora:
sha1sum
md5sum

for Ubuntu:
md5deep

In Fedora, you need to use sha1sum if sha1 hash is used by the distributors otherwise, md5sum. While Ubuntu got a "all in one" message digest program -- md5deep. Meaning it can compute md5 and sha1 hashes. Depending on the file size, these utilities might take a while to compute.

For our purpose, we need to redirect our output to a file. For example,

sha1sum Fedora-10-i386-DVD.iso > outfile.sha

We need to edit the output file (outfile.sha) so that we will just be focusing on the hash value. So, use your favourite editor and edit the output file. Remove anything that is not part of the hash. For example, this might be the output of computing the hash of Fedora 10 dvd;

086fd570518ac58d3966c43c1b6d146e38919d8d Fedora-10-i386-DVD.iso

the first part is the hash and the second part is the file name, the first part is the one we need. Remove the space following the first part and then the second part.

GO back to the web site that provided the hash value and save in another file (i.e., inetfile.sha). The two files, outfile.sha and inetfile.sha, must stored on the same path.

And this is now the time to use the diff utility. Issue the command:

diff outfile.sha inetfile.sha

If it returns nothing, then your downloaded file is OK otherwise you may need to re-download it.

Fin.

4 comments:

Balve said...

Sir,
Thanks for the time shared with your makulit trainees, the ischools lab training. I know its hard to digest everything you've said because this is not our language like what the IT and comp. sci experts do but we are ambitious enough to be one some day.
Again, thank you very much. May our link will not end with the training but it will be sustain even with or without ischools

Educ 22 - human devt said...

Dear Sir,
Thank you so much for being an awesome speaker. Thank you for your patience in teaching us. You are extraordinary because you know how to simplify complicated things... and only few teachers are like that.
I am grateful for this training because it opens another opportunity for me to learn new things...and that also entails to test my patience and perseverance.... if God willing, with good health, I plan to proceed further learning in computer education......

Unknown said...

Ma'am Balve and Ma'am Helen,

Thank you very much for your appreciation. It is in fact not easy to transfer skills to the learners. I have been trying my best to share what I know that would be helpful with all of you as you manage the ischools laboratory. I understand that all of us came from different backgrounds and I take that seriously in preparing my discussions and activities. They said that the success of a teacher in their students is when the students are able to retain what they've learned and be able to apply it to the problems that they encounter. I hope I can see that in all of you. There are still two days for us to meet and I'm looking forward to share my knowledge once again to all of you.

Balve said...

Sir,
Nice time shared to us...it will always be treasured...