Sort images by Exif Date

The exiv2 command inspects images files and prints its exif information.

$ exiv2 P1020506.JPG
File name       : P1020506.JPG
File size       : 3645104 Bytes
MIME type       : image/jpeg
Image size      : 3648 x 2056
Camera make     : Panasonic
Camera model    : DMC-FX35
Image timestamp : 2011:04:16 14:11:11
Image number    :
Exposure time   : 1/640 s
Aperture        : F5
Exposure bias   : 0 EV
Flash           : No, compulsory
Flash bias      : 0
Focal length    : 10.4 mm (35 mm equivalent: 64.0 mm)
Subject distance:
ISO speed       : 100
Exposure mode   : Auto
Metering mode   : Multi-segment
Macro mode      : Off
Image quality   : High
Exif Resolution : 3648 x 2056
White balance   : Auto
Thumbnail       : image/jpeg, 4626 Bytes
Copyright       :
Exif comment    :

Now it would be nice to sort a bunch of images automatically based on the exif information. A script in this forum that provides a shell script that sorts a bunch of images in a directory outline year/year-month-day.

The camera usually uses a number with the photo names that is incremented on each photo taken. That way the images are sorted by creation time. But it happens that photos are taken on the same day by different people and therefore by different cameras. If you then put all photos of that day in one folder, they are not sorted by creation time anymore. I then use the following script to rename the images using their date and time:

#!/bin/bash

source=$1
target=$2

if [ ! -d "$1" ]; then
  echo "Source not found."
  exit 1
fi
if [ ! -d $2 ]; then
  mkdir -p "$2" || exit 1
fi

find "$source" -iname "*.jpg" -print | while read file; do
  time=`exiv2 $file | grep "^Image timestamp" | awk '{print $4 $5}' | sed 's/://g'`
  name=`basename $file`
  cmd="cp $file $target/$time-$name"
  echo $cmd
  $cmd
done

That will rename each picture to something like 20110416180422-P1020506.JPG.

Date: [2013-06-01 Sa]

Created: 2015-12-08 Di 23:21

Validate