2

I have a bunch of images named:

1.jpg
2.jpg
317.jpg
317 (2)a.jpg
etc.

In my file browser (Nautilus), they are displayed in the correct numerical order. However, in Brasero when I order them, it orders them strangely (correctly, but not the way I want them to). They order like this:

1
10
100
101
2
20
200
201
201a
3
3a
30
300
301
.
.
.

I want to rename them so that they are displayed in the correct alpha-numerical order, so I end up with this:

1
2
3
3 (2)
3 (2)a
4
5
.
.
.
50
50 (2)
.
.
.
317 (2)a
.
.
.

Questions:

  1. Can someone recommend a naming convention to rename all these files to so they are in the correct order (for example, cameras use IMG_xxxx.JPG, which is nice)?

  2. Can someone give me a Linux command line rename command for these files so they are renamed to display and therefore burn in the correct order?

They're standard JPEG files, so ordering them by the date in the EXIF data might work. I just need the correct commands, or GUI - I don't mind - to get them in order.

Renaming them by date would probably work well enough?

3 Answers 3

4

For reordering by date, see here ("Rename a JPG by timestamp only"). Got that via Googling "rename jpeg exif linux".

0
3

It's up to the application looking at the list of files to decide how to sort them. Apparently Nautilus uses "natural order" for numeric files, while your other tools are using standard computer sorting algorithms that sort in "dictionary order" ("a" is shorter than "aardvark" so "a" comes first "b" comes after "aardvark" because "b" is higher than "a". "1" is shorter than "100" so "1" comes first. "2" comes after "100" because "2" is higher than "1").

It's entirely possible that whatever you put this CD in will ignore everything you try to do to force the files to sort one way or another. I've got an mp3 player that sorts all songs in the order they were added to the device, no matter what. If the program reading the CD sorts by filename (In my experience, most programs do dictionary sort by filename), you can force both natural and dictionary sorting to sort the files the same way by padding the filenames with enough zeros to make the numeric parts of the filenames all the same:

00001.jpg
00002.jpg
00100.jpg
00100 (01).jpg
00100 (01a).jpg
00100 (13).jpg

Then both natural sorting and dictionary sorting will come to the same result. Automating this process is going to be hard. If you removed all the parentheses and spaces and letters from the filenames, the following script would pad everything out to 5 digits (for more or less zeros change the 5 in printf %05d $n:

#!/bin/bash
set -e
for x in *; do
  e=${x##*.}
  n=${x%.*}
  nn=`printf %05d $n`
  mv "$x" "$nn.$e"
done

This will error if the filenames have anything other than digits in them though. I can't think of anything other than renaming one at a time, or doing something like rename s/^/0000/ ?.jpg rename s/^/000/ ??.jpg rename s/^/00/ ???.jpg and so on, and that still won't work well with the extra stuff at the end of your filenames.

If you want to automate the conversion you'll probably end up completely renaming them to something else (like the timestamps as the other poster suggested, as long as the timestamp is written in descending order (year month day hour minute second) they'll sort properly in dictionary order, but if there are two files with the same timestamp you might lose one if you (or your exif processing program) are not careful.

1
  • This is a very very good answer. I've found a solution already using the script given in the OP, but thank you very much for the info about sorting algorithms. The zero padding idea is one I had, but as you said, it's hard to implement. I'd upvote this answer about 5 times, but I can't :-(
    – Bojangles
    May 7, 2011 at 13:56
0

Adobe Bridge is very usefull in this case, there is some nice tools for renaming a group of files with a lot of options, You can try to find it for Linux.

5
  • Thanks for your input, however I don't have (or want to own) any Adobe products.
    – Bojangles
    May 7, 2011 at 12:28
  • Why not any adobe products? Photoshop and Premiere are both world leading pieces of software.
    – Toby Allen
    May 7, 2011 at 13:41
  • That they are, but I'd rather not pay/pirate them, as well as learning them (yes I know they're easy) when I have GIMP, Inkscape et al.
    – Bojangles
    May 7, 2011 at 13:55
  • This is a silly suggestion, as there is no Linux version of Bridge, or any other Adobe CS product. Also it would be overkill for a simple renaming task, considering the price. May 7, 2011 at 17:10
  • 1
    -1 for recommending a non-linux product to solve a linux question
    – Phil Lello
    May 7, 2011 at 18:02

You must log in to answer this question.

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