Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I make an album with pictures from several friends' cameras. Let's imagine that the EXIF exposure date and time are correct in all files. Filenames, however, are not aligned (e.g. my camera starts at IMG0001 but my friend's phone camera starts at pic1234.jpg, and my own phone starts at pic5678.jpg).

Is there a way with Shotwell to export the files from everyone over to a plain directory, with the filenames rewritten so that the pictures are sorted in chronological order? Then, when I slideshow these files in another computer, with another image viewer (or with Shotwell itself in file browsing mode), they will show in the right chronological order.

Example. If I have these six files...

  1. My camera: IMG_0001.JPG - EXIF exposure date 2012/12/25 12:05:00
  2. My camera: IMG_0002.JPG - EXIF exposure date 2012/12/25 12:11:00
  3. My own phone: pic5678.jpg - EXIF exposure date 2012/12/25 12:09:00
  4. My own phone: pic5679.jpg - EXIF exposure date 2012/12/25 12:15:00
  5. Friend's phone: pic1234.jpg - EXIF exposure date 2012/12/25 12:08:00
  6. Friend's phone: pic1235.jpg - EXIF exposure date 2012/12/25 12:18:00

...then I would like to export them with filenames like these:

  1. 20121225_120500-IMG_0001.JPG
  2. 20121225_120800-pic1234.jpg
  3. 20121225_120900-pic5678.jpg
  4. 20121225_121100-IMG_0002.JPG
  5. 20121225_121500-pic5679.jpg
  6. 20121225_121800-pic1235.jpg

so that they show in the right order when browsing with any image browser.

The following script does the trick, but is not integrated in Shotwell, which is the point of the question, and will (gracefully) fail if the pictures are not exported with Exif data:


import pyexiv2
import sys
import shutil

def getTimestamp(f):
  metadata = pyexiv2.ImageMetadata(f)
    d = metadata['Exif.Image.DateTime']
    return d.value.strftime('%Y%m%d%H%M%S')
  except Exception as e:
    return "00000000000000"

if len(sys.argv) > 1:
  for f in sys.argv[1:]:
      timestamp = getTimestamp(f)
      prefix = "%s_" % timestamp
      if f[0:len(prefix)] == prefix:
        print "File %s was already renamed, not renaming again" % (f)
        nn = "%s%s" % (prefix, f)
        shutil.move(f, nn)
        print "File %s renamed to %s" % (f, nn)
    except Exception as e:
      print "File %s not renamed (%s)" % (f, e)
  print "Usage: %s <JPG files with Exif tags>" % (sys.argv[0])
share|improve this question
This would be a great Shotwell feature. I filed a ticket here: – MrEricSir Dec 12 '12 at 23:08

The easiest approach will be to break this into two parts.

  • First, export all the images from Shotwell to one folder.

  • Second, use pyrenamer to give the files the naming pattern you want.

Here's an example of how to use pyrenamer:

pyrenamer ui

Here's the code I used to try to match your example in your question:


It produces filenames that look like this:

pyrenamer output sample

Notice that you can add characters between the values in the curly brackets (like the underscore between {imageday} and {imagehour}), to make the output easier to read.

The last {num3+1} bit is optional but helps if you happen to have two photos shot at the same second, and makes the whole lot easier to read.

If you do this and find that one or more of the device clocks are off, you can use Shotwell to modify the time/date, and then re-do the pyrenamer step to have everything in perfect order. This is especially helpful for something like a wedding where people are coming to the event from different time zones, and photos out of order look totally wrong.

Last, don't forget to include the file extension on the end, or it will be removed and may cause other problems.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.