Linux Format forums Forum Index Linux Format forums
Help, discussion, magazine feedback and more
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Batch Renaming of Files [solved]

 
Post new topic   Reply to topic    Linux Format forums Forum Index -> Help!
View previous topic :: View next topic  
Author Message
Fat_Tuesday



Joined: Mon Oct 09, 2006 1:14 pm
Posts: 89

PostPosted: Sun Apr 21, 2013 1:46 pm    Post subject: Batch Renaming of Files [solved] Reply with quote

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 3:58 pm; edited 1 time in total
Back to top
View user's profile Send private message
nelz
Site admin


Joined: Mon Apr 04, 2005 12:52 pm
Posts: 8453
Location: Warrington, UK

PostPosted: Sun Apr 21, 2013 2:53 pm    Post subject: Reply with quote

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)
Back to top
View user's profile Send private message
Fat_Tuesday



Joined: Mon Oct 09, 2006 1:14 pm
Posts: 89

PostPosted: Sun Apr 21, 2013 3:33 pm    Post subject: Reply with quote

Haha, not secret, was going to use anything incremental really. 0001.jpg upwards would be sufficient.
Back to top
View user's profile Send private message
Fat_Tuesday



Joined: Mon Oct 09, 2006 1:14 pm
Posts: 89

PostPosted: Sun Apr 21, 2013 3:46 pm    Post subject: Reply with quote

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

Code:
#!/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

Back to top
View user's profile Send private message
View previous topic :: View next topic  
Display posts from previous:   
Post new topic   Reply to topic    Linux Format forums Forum Index -> Help! All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Linux Format forums topic RSS feed 


Powered by phpBB © 2001, 2005 phpBB Group


Copyright 2011 Future Publishing, all rights reserved.


Web hosting by UKFast