Sometimes it happens that you collect photos from a couple or more cameras (for example from your friends), and of course they're named with their own names, for example
IMG_6767.JPG P1102188.jpg SnowTrip-0023.JPG
because of different vendor conventions and sometimes because they've already been renamed.
Some good photo viewers can show your photos ordered my date (not the file date, the date in which the photo has been taken), but most of them just sort them alphabetically.
For this reason I wrote the following script, that just renames ALL the photos in the same way, that is
SnowTrip_20080123104105.jpg
for a picture that has been taken on January 23rd, 2008 at 10:41:05. What you need is the exifdump script and a tiny tiny script I wrote.
Exifdump
This is a script I found online. I'm linking it here because you cannot find it in a lot of places online. Proper credit has to be acknowledged, though, so this is the home page of the author, Thierry Bousch.
What this script does is to retrieve from the given photo all the EXIF data that are stored in it. This info goes from date, time, camera, shutter time, exposure, etc... Give a look to exif.org for a full list of the available fields.
My script
This is the tiny script that I use to automatically rename all the photos in a given folder with the convention I explained above.
#!/bin/bash
prefix=$1
for file in `dir -d *.jpg *.JPG *.jpeg *.JPEG 2> /dev/null` ; do
datetime=`exifdump.py "$file" | grep "DateTimeOriginal" | tr -d ...
... "DateTimeOriginal(A)=': "`
newname="${prefix}_${datetime}.jpg"
if [ ! -w $newname ]; then
mv $file $newname
fi
done
You can download it here (copying and pasting won't work because of the dots).
You can see that this is really the simplest script one can write for this purpose. Extra features that are straightforward to add are
- working on given files instead of all the files in the directory
- using extra EXIF information to be included in the filename
- dealing with duplicates
- much more!
I hope you liked this page!
If you think it did help you, why don't you buy me a spritz ? ;-)

