Advanced

How to Sort and Remove Duplicate Photos in Linux

Posted by tuxchick on · 3 comments
Linux.com; By Carla Schroder
Mail this story
Print this story

In the olden days of photography we thought were ready for anything with a few 36-exposure film cassettes in our bags. Now we can capture gigabytes of photos in just a few minutes, without reloading. I have a 32GB card in my camera, which holds 1700+ RAW images at 18MB each. Don't worry, I won't make you look at all of them. Heck, I don't even know what I have. Over the years I've created duplicates by dumping them onto my computer when I was in a hurry, and making backups without rhyme or reason, so I want to hunt down all the duplicates and get rid of them. But I'm looking at 205GB of photos:

Full Story

  Nav
» Read more about: Story Type: Tutorial; Groups: Linux

» Get new stories by e-mail: nightly or as they are published

« Return to the newswire homepage

  Related stories
» More like this

Comments (3)

... I'm not the only person who has multiple copies of photos in copied into directories like 20140523, 20140524, etc. because I failed to reformat the card after the last time I dragged all the photos onto my hard disk. I was unaware that a couple of these utilities for finding dupes existed. (Might have saved me from having written several similar utilities myself.)

Next problem: dealing with photos that are being offloaded from several cameras and have similar naming conventions. One of these days I'm going to be offloading photos from two cameras and find that there are duplicate filenames for different photos. Something based on exiftool to rename the photos as they're copied from the memory cards that uses the camera brand and model in the filename would be the ticket.
md5sum is your friend:

$ find /path/to/photos/ -type f | wc -l

$ find /path/to/photos/ -type f | xargs md5sum | awk '{print $1;}' | sort | uniq | wc -l

If the numbers from these two commands are different, you likely have dupes somewhere.
with tens of thousands of photos knowing that there are dupes is not very helpful.

also, md5sum is expensive, you can compare files by size. we only need to compare files of the same size. takes a bit more scripting to work that out but may be worth the effort with lots of files. and then, if the sizes match, unless there are more than a few files of a particular size, using cmp may still be faster than md5sum. for md5sum the whole file needs to be read. cmp will abort as soon as a single byte differs. cmp handles only 2 files at once though, so to compare more than two files you need to open the same file multiple times. with more than say 4 files of the same size, i'd use md5sum too.

btw: useless use of xargs, with find. the best way to use it is:

find /path/to/photos/ -type f -exec md5sum \{\} \+
using \+ makes exec work like xargs and run md5sum with as many arguments as allowed.

greetings, eMBee.

Post a comment

A free account is needed to post. Write your comment here first: your text is kept in this browser while you sign up or log in, and is waiting for you when you come back.

Your message:
|||||
10
Markdown: **bold**, *italic*, [text](https://link), - lists, > quotes, $x^2$ for math. Formatting help

Sign up and post (it is free)  or  Log in and post