Command Line One-Liner to Compare Files with MD5
While working on a tool to eliminate duplicate photos from old hard drives, I wrote this little snippet of code that’s worth saving:
if [ $(md5 -q 1.txt) == $(md5 -q 2.txt) ]; then echo "same"; else echo "different"; fi
It’s a command line one-liner that generates MD5 hashes for two files, compares them and states if they are the same or different.
For those unfamiliar with MD5, it’s a “cryptographic hash function that produces a 128-bit hash value.” The useful part for this snippet is that MD5 can be fed a file of any size and the results is a 32 character string. Most importantly, the same input will always produce the same output and any difference (no matter how minor) creates a large difference in the result. For example, any computer can run MD5 on a file with the contents “asdfasdf-1” and it will produce the hash signature:
f3748c05e25ca8cce7795d1ec97749b0
If you change the one to a two (i.e. “asdfasdf-2”) the signature changes to:
e9ca151e1882f63c5d05e7958a7527a9
More about this will come in another post, but what this means for a duplicate photo finder is that MD5 hashes can be generated for every photo and then compared. Any two files with the same hash signature are the same* and can be pared down. That is done with a larger program. The little snippet of code is used for verification. It’s also useful enough to be broken out to its own.
*Note: For the tech/cryptography minded folks out there, I know that MD5 can have collisions. For what I’m doing, the chances are so small that I’m not worried about it.
2013
Random Related Links
Identity Theft Protection by opting out
Aside from snuffing out a huge portion of you junk mail another benefit of opting out via optoutprescreen.com is that it reduces the…
- Miscellaneous
Juggling
Some day, I'm going to teach myself how to juggle. I don't think I'll ever get quite to this level though.
- Miscellaneous
Zip Codes
If you ever want to know where a zip code actually is, you can use this: http://maps.huge.info/zip.htm
- Miscellaneous
Can see shit
Inspired by Nuge's "Can't see shit" , I figured it would be a good time to contrast our weather again. So, here's a shot I took out of my…
- Miscellaneous
Quote on photography
All photographs are accurate. None is the truth. - Richard Avedon
- Miscellaneous
That's Not Photoshop
Here's one of the images I was scanning. One of my favorites out of all the ones I've ever shot. Yes. The flames are real. Dave ended up…
- Miscellaneous
Yep. Found a lab.
And we have a winner: whcc.com These guys a really smart. They ask you to send in up to 5 8x10s for them to print as a test. Part of this…
- Miscellaneous
Hey Look, Some Photos
Probably obvious by this point, but I'm actually making a little progress in things other than work over the past few days. It's a…
- Miscellaneous
Next Digital Step
If someone wants to buy me a really expensive present, this would do just fine: http://www.dpreview.com/articles/canoneos5d/ Full of digital…
- Miscellaneous
C-Nets URLs
This is one of the best setups for URLs that I've seen before. Take the following URL as an example: http://news.com.com/Passport+to+get…
- Miscellaneous
Quality Music: The Meters
Cissy Strut by The Funky Meters just came up on the random. It might actually be impossible to keep your head from bobbing when you listen…
- Miscellaneous
Command Line One-Liner to Compare Files with MD5
Quick bash line to compare two files via MD5
- Miscellaneous
Fever Dreams
I've had some weird illness over the past couple days. Not sure what it is. Doesn't feel quite like a cold or the flu, but I suppose it…
- Miscellaneous
Dimmable CFL
I switched over most of the lights in my house to compact fluorescent light bulbs a while ago. I've been quite pleased with them though the…
- Miscellaneous
Good little (open source) clip art site
While looking for an open source clip art light-bulb the first site google returned was openclipart.org . However, it looks like they are…
- Miscellaneous
Using mysqldump on Mac OS X Leopard
Originally found this here after lots of searching. Making my own link to make sure I can find it again. To use mysqldump on a Mac running…
- Miscellaneous
Clear Cache Button - Firefox extension
One more Firefox extension to help out anyone who does web development work or is otherwise interested in a quick way to clear your Firefox…
- Miscellaneous
Sudoku - for when you want to drive yourself mad
I've heard of Sudoku before, but never saw a free online version to play till today. Granted, I hadn't really looked. When I stumbled on…
- Miscellaneous
McDonald's Marketing
A friend with a four year old daughter has done his best to keep McDonald's out her world. She has never been in one, and he does his best…
- Miscellaneous
Part 2?
Netflix just threw up "Final Destination 2". Funny. I suppose the first one wasn't so Final after all. I think I saw part of the first one…
- Miscellaneous
Moonlanding On Windows
Everthing changed. Or, really, I changed everything. ` I'm writing this on my new [Moonlander keyboard. It's a while ride. A split…
- Miscellaneous
Internet find: Electronics Training from the Navy
United States Navy Electricity & Electronics Training Series - NEETS * In the introduction, the texts are defined as a "self-study course…
- Miscellaneous
Safer Internet Purchases
One of the fears of making a purchase over the internet is giving out your credit card information. After all, you have to send them all the…
- Miscellaneous
Something Happy
Not to end the night on a downer. It's going to be Friday in 21 min. which means only 8 or so hours of work will the weekend.
- Miscellaneous
Quixotic
I forgot how to pronouce the word "Quixotic" and was asking an office mate if he knew, but he didn't. Turning to the magic of the net I…
- Miscellaneous
First Post - Yeah, yeah
I finally broke down and started a blog. I figure I run across some neat things from time to time and this would be a good way for me to…
- Miscellaneous
Degrading The Shopping Experience As Best They Can
Here's a run down of today's interaction with a cashier at the mall. This is why I do most of my shopping online. To set the stage, I was…
- Miscellaneous
I have no faith in "Lost"
I just read a post titled " How Lost bends the rules " on Boing Boing . I'm one of the people the article talks about that dropped out of…
- Miscellaneous
Outsourcing
For the past few years, the talk of Outsourcing to foreign companies has been increasing at a steady rate. One reassuring aspect is that if…
- Miscellaneous