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 bunch of images named:

317 (2)a.jpg

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:


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

3 (2)
3 (2)a
50 (2)
317 (2)a


  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?

share|improve this question

migrated from serverfault.com May 7 '11 at 11:58

This question came from our site for system and network administrators.

3 Answers 3

up vote 4 down vote accepted

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

share|improve this answer
Thanks very much :-) This is perfect. –  Bojangles May 7 '11 at 12:09

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:

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:

set -e
for x in *; do
  nn=`printf %05d $n`
  mv "$x" "$nn.$e"

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.

share|improve this answer
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 '11 at 13:56

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.

share|improve this answer
Thanks for your input, however I don't have (or want to own) any Adobe products. –  Bojangles May 7 '11 at 12:28
Why not any adobe products? Photoshop and Premiere are both world leading pieces of software. –  Toby Allen May 7 '11 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 '11 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. –  Liquid_Fire May 7 '11 at 17:10
-1 for recommending a non-linux product to solve a linux question –  Phil Lello May 7 '11 at 18:02

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.