Batch Renaming of Files [solved]

The place to post if you need help or advice

Moderators: ChrisThornett, LXF moderators

Batch Renaming of Files [solved]

Postby Fat_Tuesday » Sun Apr 21, 2013 12:46 pm

Hi all,

I'm using ubuntu 12.10 and have a folder that contains a hundred or so .jpg files of varying names and lengths. I'd like to rename them all to a standard (and keep the .jpg). I've tried researching rename and other bash options but they generally assume that the files already have some kind of standard naming convention to work off. I don't. So my question is this: how do I use bash to blanket rename everything in that directory to my new naming convention?

TIA
Last edited by Fat_Tuesday on Sun Apr 21, 2013 2:58 pm, edited 1 time in total.
Fat_Tuesday
 
Posts: 97
Joined: Mon Oct 09, 2006 12:14 pm

Postby nelz » Sun Apr 21, 2013 1:53 pm

That rather depends on the details of your new, but apparently top secret, naming convention.
"Insanity: doing the same thing over and over again and expecting different results." (Albert Einstein)
User avatar
nelz
Site admin
 
Posts: 8504
Joined: Mon Apr 04, 2005 11:52 am
Location: Warrington, UK

Postby Fat_Tuesday » Sun Apr 21, 2013 2:33 pm

Haha, not secret, was going to use anything incremental really. 0001.jpg upwards would be sufficient.
Fat_Tuesday
 
Posts: 97
Joined: Mon Oct 09, 2006 12:14 pm

Postby Fat_Tuesday » Sun Apr 21, 2013 2:46 pm

Ok, I managed it (and got my first ever bash script working in the process, hooray!). I'll include it here for reference ...

Code: Select all
#!/bin/bash

a=1
for i in *.jpg; do
  new=$(printf "scan_%04d.jpg" ${a}) #04 pad to length of 4
  mv ${i} ${new}
  let a=a+1
done

Fat_Tuesday
 
Posts: 97
Joined: Mon Oct 09, 2006 12:14 pm


Return to Help!

Who is online

Users browsing this forum: Narendra and 0 guests