Super User is a question and answer site for computer enthusiasts and power users. 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 have a mess in my photos folder; I want to sort them according to date in EXIF information and rename according to the date (like 001.jpg, 002.jpg and so on).

How can I do this in Linux? I have used ImageMagick for some basic bulk processing tasks before (converting and resizing, etc), is it possible to use it for this task?

share|improve this question

On Linux you can use the command exiftool. For some reason the online manual does not contain the "RENAMING EXAMPLES" section which gave me the essential hint.

For JPG only files the following command invocation should do the job:

exiftool -r '-FileName<CreateDate' -d '%Y-%m-%d/%H_%M_%S%%-c.%%le' <yourFolder>


  • -r is for recursion
  • '-FileName<CreateDate' tells exiftool to rename the file accordingly to its EXIF tag CreateDate (you can try others like ModifyDate though)
  • -d '%Y-%m-%d/%H_%M_%S%%-c.%%le' tells how to build the filename string from the date source "CreateDate" (the "%-c" will append a counter in case of file collisions, the "%le" stands for "lower cased file extension")
    • Note: I used "-FileName<..." here for renaming the files and moving it to another folder within one step. The manual points out that you have to use the "-Directory<..." syntax for folder operations. It worked for me this way though.

You should spend some time reading the manual of this powerful tool. Maybe there is an even shorter way :D

share|improve this answer

Try this free product: AmoK Exif Sorter.

share|improve this answer

The most simple way is to just import files into jbrout ... then (optionally) all files can have names changed to something time oriented. Or you may find, that you do not need changing names at all (and jbrout is sufficient).

share|improve this answer

I did a small and not very optimized python script that at I think does what you intend:

1 import pyexiv2, sys, os, time, datetime, random
2 dirname = sys.argv[1]
3 flist=os.listdir(dirname)
4 dic = dict()
5 for fname in flist:
6     metadata = pyexiv2.ImageMetadata(sys.argv[1]+'/'+fname)
8     tag = metadata['Exif.Image.DateTime']
9     timestamp = int(time.mktime(tag.value.timetuple()))
10     #print fname, ' ', tag.value, ' ', timestamp
11     try:
12         dic[timestamp] = fname
13     except:
14         print fname, ' not processed.'
16 keys = dic.keys()
17 keys.sort()
18 i = 0 
19 for k in keys:
20     os.rename(sys.argv[1]+'/'+dic[k], sys.argv[1]+'/'+str(i)+'.jpg')
21     i+=1
share|improve this answer
You have to install this library – celebdor Oct 31 '10 at 12:50

To make it work in Debian Lenny try this:

import pyexiv2, sys, os, time, datetime, random
dirname = sys.argv[1]
dic = dict()
for fname in flist:
    image = pyexiv2.Image(sys.argv[1]+'/'+fname) 
    #metadata = pyexiv2.ImageMetadata(sys.argv[1]+'/'+fname)
    tag = image['Exif.Image.DateTime']
    timestamp = int(time.mktime(tag.timetuple()))
    #print fname, ' ', tag.value, ' ', timestamp
    dic[timestamp] = fname
    print fname, ' not processed.'

keys = dic.keys()
i = 0 
for k in keys:
    os.rename(sys.argv[1]+'/'+dic[k], sys.argv[1]+'/'+str(i)+'.jpg')
share|improve this answer

In php I did something like this:


$path = "./path/to/images";
$files = scandir($path);

foreach ( $files as $file )
    if ( $file[0] === "." )
    $ext = end(explode(".", $file));

    $suffix = "image";

    $exif = exif_read_data($path."/".$file, 'EXIF');
    $datetime = str_replace("/","-", $exif['DateTimeDigitized']);

    rename($path."/".$file, $path."/".$datetime.$suffix.".".$ext);
share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .