My camera names its images IMG_0001.jpg, IMG_0002.jpg, IMG_0003.jpg, etc.

I have about a thousand images and would like to rename them without having to do it manually if possible.

Is there a good way to automate the process of renaming them in the reverse order - e.g. IMG_0003.jpg, IMG_0002.jpg, IMG_0001.jpg?

  • Did you get an answer to your question? It's important for the site to accept an answer if it works for your needs. Not only does it help others with the same question, it rewards the answerer in addition to the upvotes the community has given them.
    – bmike
    Oct 28, 2012 at 22:29
  • Sorry - still haven't had a chance to test it out yet. I will accept one when I figure it out.
    – Jason
    Oct 29, 2012 at 18:08
  • Thank you. You can also accept the most useful answer and comment that you have not had time to test. Should it change, you can always un-accept an answer and delete a comment that is out of date. Cheers and thanks for keeping the site fed with feedback.
    – bmike
    Oct 29, 2012 at 18:11

5 Answers 5


You can use an Automator Workflow.

Something like this:

enter image description here

Sort Finder Items step will sort image names descending (IMG_0003.jpg, IMG_002.jpg, IMG_001.jpg).

Make Sequential step will rename them sequentially (IMG_0001.jpg, IMG_0002.jpg, ...).

Copy Finder Items step is optional, just to be sure not to mess with original files.

  • amaaaaaaaaazing.. love you
    – MFarooqi
    Nov 23, 2017 at 18:17

Here's another shell script. You can save it as a normal text file and then run bash /path/to/script.sh from Terminal. Remove the echo to actually rename the files.

cd ~/Pictures/
IFS=$'\n' # the input field separators include space by default
for f in $(ls -r IMG*.jpg); do 
    echo mv "$f" "IMG_$(printf %04d $i)".jpg
    (( i++ ))

Try this in the Terminal:

mkdir new
ls IMG* > 1
sort -r < 1 > 2
paste 1 2 | awk '{ print "mv " $1 " new/" $2} ' > 3
. 3

The renamed files will be in the new folder.

Here is a brief explanation of how this works: it creates a script named 3 that does the renaming. For that, it creates a listing of the images in alphabetical order in 1 and in reverse order in 2. Then one line is read from each file and combine into a mv command, which is executed when you run 3. The images are renamed into the new folder to avoid collisions.

  • The answser lhf gavin was right, but before step 5, you should exec chmod +x 3 first.
    – lyuehh
    Oct 18, 2012 at 14:39
  • Consider explaining what each step of the script does Oct 18, 2012 at 22:40

Name Mangler ($10 and has a free trial) or Name Changer (free/donationware) is also very good for this sort of thing if you're after a nice, simple app.


You can use the perl rename.pl script looming around the web (for example, from here), and put it into the folder with your image files.

Its usage is simple and documented and it is pretty powerful. To use it for your case, replace MAXIMUM_NUMBER by the number in the last photo, then run:

perl rename.pl 's/IMG_0+(\d+)/"A_IMG_".sprintf("%04d",(MAXIMUM_NUMBER- $1))/xe' *.jpg && perl rename.pl 's/A_//' *.jpg

To explain:

  1. The first rename (before &&) will rename all files to MAXIMUM_NUMBER minus the number already in the file name. It will also prefix the filename with A_ in order to avoid overwriting already existing files.
  2. The second rename simply deletes the A_ from the file names.

Note that the rename.pl script can do much more than that if you ever need more complex renaming.

You must log in to answer this question.

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