Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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

6 Answers 6

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)
7     metadata.read()
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.'
15 
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 tilloy.net/dev/pyexiv2 –  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]
flist=os.listdir(dirname)
dic = dict()
for fname in flist:
    image = pyexiv2.Image(sys.argv[1]+'/'+fname) 
    #metadata = pyexiv2.ImageMetadata(sys.argv[1]+'/'+fname)
    #metadata.read()
    image.readMetadata() 
    tag = image['Exif.Image.DateTime']
    timestamp = int(time.mktime(tag.timetuple()))
    #print fname, ' ', tag.value, ' ', timestamp
    try:
    dic[timestamp] = fname
    except:
    print fname, ' not processed.'

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

In php I did something like this:

<?php

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

foreach ( $files as $file )
{
    if ( $file[0] === "." )
    {
        continue;
    }
    $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

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>

Explanation:

  • -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

Your Answer

 
discard

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.