I think, therefore I blog

Re-Order Photos Using Bash

By , 12 November 2010

Re-Order Photos Using Bash

Here's a script I used to use to renumber the files in a directory according to their modification date.


# Renames the files in the current directory to a 4 digit number
# which is their position in the directory multiplied by 10.
# This script is meant to help sort photos in your albums.
# Specify a starting number on the command line if you want to start
# at another number other than zero.
# If a second number is specified, this step value is used. Otherwise
# a step value of 1 is used


for i in `ls -t .`; do
    newname=`printf "%03d" $c`.`echo ${i:${#i}-3} | tr 'A-Z' 'a-z'`
    mv "$i" $newname
    c=`expr $c + $s`
Re-Order Photos Using Bash

About Roger Keays

Re-Order Photos Using Bash

Roger Keays is an artist, an engineer, and a student of life. Since he left Australia in 2009, he has been living as a digital nomad in over 40 different countries around the world. Roger is addicted to surfing. His other interests are music, psychology, languages, and finding good food. Click here to subscribe to his weekly blog, or stalk him on Facebook and Twitter.

Leave a Comment

Please visit https://RogerKeays.com/blog/re-order-photos-using-bash to add your comments.

Join Over 1000 Subscribers

I write every Sunday about travel, psychology, and technology. Thousands of people just like you have already subscribed—and for good reason. It'll change your life. And it's free :)

Read a Good Book

“A spellbinding true story of love, passion and adventure. One can’t help but be swept away by 100% Love Guaranteed.” —Dr Tammie Matson, author of Elephant Dance.

Chat For A While

Your Vote Matters

Which animal will take over when humans go extinct?