Frank Ridderbusch


About things, that are of interest to me (in English and in German).


Importing and Organizing Photos with exiftool

Until recently I’ve been using Digikam to organise and rename my digital photos, sorting them into directories and so on. With my recent move to the KDE5/QT5 desktop environment, the stable 4.x Digikam needed uninstalling due to some dependency collision on my Gentoo Linux installation.

But in the meantime, I’ve found, that ExifTool is actually quite superior for importing and organising for photo files from the camera. Here is how I do it.

Photo organization

My personal preferred directory structure for cataloguing my photos is as follows:

|-- 450D
…
`-- 70D
    |-- 2015-10-10-Denmark-Vacation
    |   |-- raw
    |   |   |-- 2015-10-10-124021-5605.CR2
    |   |   …
    |   |   `-- 2015-10-10-134435-5610.CR2
    |   `-- print
    |       |-- 2015-10-10-124021-5605.CR2
    |       …
    |       `-- 2015-10-10-134435-5610.CR2

At the top level is the camera model directory (I’ve now owned 4 digital cameras, all from Canon: G3, 350D, 450D and 70D). Below that is a directory starting with the date in ISO format and a short descriptive tag indicating the situation (vacation-in-… or birthday-of-…).

I could have chosen to create even more levels of directories, but the number of photos I’m shooting doesn’t warrant a still finer substructure.

Under this directory I’m creating a raw and a print directory. The raw directory will, of course, contain the RAW pictures directly from the digital sensor and the print directory will hold the final “ready to print” version of the image typically developed with either Corel Aftershot Pro or Darktable. In case I’ve setup the camera to record both RAW and JPG formats at the same time, the JPGs from the camera will also go into the print folder.

Finally, the pictures are named after their creation date starting with the ISO date string of the date followed be the time string. The last 4 digit number just before the extension are from the original file name assigned by Canon. Canon files are named like IMG_5605.CR2. I like to keep this number in the file name.

Doing it with ExifTool

ExifTool is a powerful tool, with many options. Due to the rich set of features, it might be not easy to get your command line right the first time.

So, with the scheme from above in mind, three ExifTool invocations are required. I’m changing directory into the camera base directory first.

cd ~/graphics/70d

/run/media/fgth/EOS_DIGITAL is the mount point, where the SD card gets mounted when it gets inserted into the card reader and which contains the pictures in a subdirectory. The first invocation selects the raw files (-ext CR2) and copies (-o .) them into the destination directory (-d %Y-%m-%d-Denmark-Vacation/raw). Without the -o . the picture files would be moved instead of copied. The CreateDate data from the picture EXIF data replaces the format specifiers of the -d option.

exiftool -o . '-Directory<CreateDate' -ext CR2 -d %Y-%m-%d-Denmark-Vacation/raw \
    /run/media/fgth/EOS_DIGITAL/DCIM/100CANON/
exiftool -o . '-Directory<CreateDate' -ext JPG -d %Y-%m-%d-Denmark-Vacation/print \
    /run/media/fgth/EOS_DIGITAL/DCIM/100CANON/

The second invocation works similarly. Now the JPG files (-ext JPG) are copied into the print directory.

Finally, all the images will be renamed to the intended name format with two shell wildcard operations (*-Denmark-Vacation/*/*), one for JPGs and one for the CR2 raw files.

exiftool '-FileName<${CreateDate}-$fileindex.JPG' -ext JPG -d %Y-%m-%d-%H%M%S \
    *-Denmark-Vacation/*/*
exiftool '-FileName<${CreateDate}-$fileindex.CR2' -ext CR2 -d %Y-%m-%d-%H%M%S \
    *-Denmark-Vacation/*/*

A quickly hacked together shell script (without enough error checking) should look like this:

#!/bin/bash

if [[ $# != 2 ]] ; then
    echo "not enough arguments"
    exit 1
fi

desctag="$1"
mntpoint="$2"

dirfmt="%Y-%m-%d"
filefmt="%Y-%m-%d-%H%M%S"

exiftool -o . '-Directory<CreateDate' -ext CR2 -d "${dirfmt}-${desctag}/raw" \
    $mntpoint
exiftool -o . '-Directory<CreateDate' -ext JPG -d "${dirfmt}-${desctag}/print" \
    $mntpoint
exiftool '-FileName<${CreateDate}-$fileindex.JPG' -ext JPG -d "${filefmt}" \
    *-${desctag}/*/*
exiftool '-FileName<${CreateDate}-$fileindex.CR2' -ext CR2 -d "${filefmt}" \
    *-${desctag}/*/*