The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
.
google unix.com



UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Renaming Multiple files dhiren_shah UNIX for Dummies Questions & Answers 2 09-12-2008 02:23 AM
Renaming multiple files amit4g Shell Programming and Scripting 2 07-14-2008 09:36 AM
Renaming of multiple filenames shashi_kiran_v UNIX for Dummies Questions & Answers 7 07-05-2005 09:33 AM
Renaming multiple files rmayur UNIX for Dummies Questions & Answers 6 02-26-2004 04:40 AM
Renaming multiple files jxh461 Shell Programming and Scripting 4 04-01-2003 07:25 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 10-07-2008
BigTool4u2 BigTool4u2 is offline
Registered User
  
 

Join Date: Nov 2002
Location: London
Posts: 31
Multiple file renaming

Hi All,

I have a number of files in a directory that I would like to rename - I am quite aware that you can use the mv command to rename the files - I would like to rename them automatically from the command line instead of having to do them singly. I have searched the forum pertaining to renaming multiple files but they do not seem to do what I want. What I would like to do is change the name of the file to whatever name I want for example Cuba1.JPG Cuba2.JPG etc etc. The files which I want to rename is shown below.

IMAG0001.JPG
IMAG0002.JPG.ext2.ext2.ext2
IMAG0003.JPG.ext2.ext2.ext2
IMAG0005.JPG.ext2.ext2.ext2
IMAG0006.JPG.ext2.ext2.ext2

Any help is appreciated.

Rgds.
  #2 (permalink)  
Old 10-07-2008
ghostdog74 ghostdog74 is offline Forum Advisor  
Registered User
  
 

Join Date: Sep 2006
Posts: 2,553
if you have Python, you can use the script here
example usage
Code:
# ls -1
IMAG0001.JPG
IMAG0002.JPG.ext2.ext2.ext2
IMAG0003.JPG.ext2.ext2.ext2
IMAG0005.JPG.ext2.ext2.ext2
IMAG0006.JPG.ext2.ext2.ext2

 ## filerenamer.py -s "IMAG(\d+)\.JPG.*" -e "CUBA01:99.JPG" -l -n "IMAG*" #remove -l to commit
==>>>>  [ /home/IMAG0001.JPG ]==>[ /home/CUBA01.JPG ]
==>>>>  [ /home/IMAG0002.JPG.ext2.ext2.ext2 ]==>[ /home/CUBA02.JPG ]
==>>>>  [ /home/IMAG0003.JPG.ext2.ext2.ext2 ]==>[ /home/CUBA03.JPG ]
==>>>>  [ /home/IMAG0005.JPG.ext2.ext2.ext2 ]==>[ /home/CUBA04.JPG ]
==>>>>  [ /home/IMAG0006.JPG.ext2.ext2.ext2 ]==>[ /home/CUBA05.JPG ]
 
# filerenamer.py -s "IMAG(\d+)\.JPG.*" -e "CUBA01:99.JPG"  -n "IMAG*"
/home/IMAG0001.JPG  is renamed to  /home/CUBA01.JPG
/home/IMAG0002.JPG.ext2.ext2.ext2  is renamed to  /home/CUBA02.JPG
/home/IMAG0003.JPG.ext2.ext2.ext2  is renamed to  /home/CUBA03.JPG
/home/IMAG0005.JPG.ext2.ext2.ext2  is renamed to  /home/CUBA04.JPG
/home/IMAG0006.JPG.ext2.ext2.ext2  is renamed to  /home/CUBA05.JPG


# ls -1
CUBA01.JPG
CUBA02.JPG
CUBA03.JPG
CUBA04.JPG
CUBA05.JPG

Last edited by ghostdog74; 10-07-2008 at 08:40 PM..
  #3 (permalink)  
Old 10-08-2008
BigTool4u2 BigTool4u2 is offline
Registered User
  
 

Join Date: Nov 2002
Location: London
Posts: 31
Multiple file renaming

Quote:
Originally Posted by ghostdog74 View Post
if you have Python, you can use the script here
example usage
Code:
# ls -1
IMAG0001.JPG
IMAG0002.JPG.ext2.ext2.ext2
IMAG0003.JPG.ext2.ext2.ext2
IMAG0005.JPG.ext2.ext2.ext2
IMAG0006.JPG.ext2.ext2.ext2

 ## filerenamer.py -s "IMAG(\d+)\.JPG.*" -e "CUBA01:99.JPG" -l -n "IMAG*" #remove -l to commit
==>>>>  [ /home/IMAG0001.JPG ]==>[ /home/CUBA01.JPG ]
==>>>>  [ /home/IMAG0002.JPG.ext2.ext2.ext2 ]==>[ /home/CUBA02.JPG ]
==>>>>  [ /home/IMAG0003.JPG.ext2.ext2.ext2 ]==>[ /home/CUBA03.JPG ]
==>>>>  [ /home/IMAG0005.JPG.ext2.ext2.ext2 ]==>[ /home/CUBA04.JPG ]
==>>>>  [ /home/IMAG0006.JPG.ext2.ext2.ext2 ]==>[ /home/CUBA05.JPG ]
 
# filerenamer.py -s "IMAG(\d+)\.JPG.*" -e "CUBA01:99.JPG"  -n "IMAG*"
/home/IMAG0001.JPG  is renamed to  /home/CUBA01.JPG
/home/IMAG0002.JPG.ext2.ext2.ext2  is renamed to  /home/CUBA02.JPG
/home/IMAG0003.JPG.ext2.ext2.ext2  is renamed to  /home/CUBA03.JPG
/home/IMAG0005.JPG.ext2.ext2.ext2  is renamed to  /home/CUBA04.JPG
/home/IMAG0006.JPG.ext2.ext2.ext2  is renamed to  /home/CUBA05.JPG


# ls -1
CUBA01.JPG
CUBA02.JPG
CUBA03.JPG
CUBA04.JPG
CUBA05.JPG
Thanks for your reply - I have python running on my system and it's the 1st time I've used it to be honest. Needless to say I do not know anything about it. The script that you've written, can it be used on any flavour of UNIX - I am using Mac OS X, I'm not sure if that has anything to do with the output which I'm getting of whether I do not know how to run the actual script.

I have tried t run it by copying the lines of code then pasting it in at the python prompt. When that happens I get the error

>>> [ /Users/johndoe/Desktop/Test/Picturefolder/IMAG0001.JPG ]==>[ /Users/johndoe/Desktop/Test/Picturefolder/CUBA01.JPG ]
File "<stdin>", line 1
[ /Users/johndoe/Desktop/Test/Picturefolder/IMAG0001.JPG ]==>[ /Users/johndoe/Desktop/Test/Picturefolder/CUBA01.JPG ]
^
SyntaxError: invalid syntax
>>>

What am I doing wrong here?

Thanks & Rgds.
  #4 (permalink)  
Old 10-08-2008
era era is offline Forum Advisor  
Herder of Useless Cats (On Sabbatical)
  
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,652
Looks like you copy+pasted the example result rather than the actual code. The script you want is available from the link behind the text "here" in ghostdog74's posting; visit the web page and you'll find a piece of code which you can "save as" filerenamer.py -- it begins with the following

Code:
#!/usr/bin/env python
import sys,os,getopt,glob,string,re,operator,fnmatch,time
etc.

Save into a file, chmod +x the file, and go.
  #5 (permalink)  
Old 10-09-2008
ghostdog74 ghostdog74 is offline Forum Advisor  
Registered User
  
 

Join Date: Sep 2006
Posts: 2,553
save the script as filerenamer.py and make sure its executable, then you can either use ./filerenamer.py ... or python filerenamer.py <options>
I have got the script copied to one of the directories in my PATH variable, that's why i can use just "filerenamer.py"
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 06:15 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0