LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 06-30-2007, 05:27 AM   #1
karnaf
Member
 
Registered: Dec 2005
Distribution: Linux Mint 14 (Cinnamon), Xubuntu 12.04, Ubuntu 10.04
Posts: 49

Rep: Reputation: 15
Rename problems....


Searched many of the threads here trying to figure out how to use rename function, also checked the man and info pages, to no avail.

I've got a folder with plenty of mp3 tracks. The problem is many of them have multiple spaces in the name and the extension is in CAPS. So I thought I'd start little by replacing all extensions to lower case.

Following the rename example from the man pages, I tried this, but it didn't work
Code:
rename .MP3 .mp3 *.MP3
Searching a little the web, I've encountered the following format, which didn't work either
Code:
rename 's/\.MP3/\.mp3/g' *.MP3
I've checked my syntax using sed which echoed the right results, but of course, did not rename the files
Code:
ls -R | sed 's/\.MP3/\.mp3/g'
What am I missing?

Thanks,
karnaf

p.s. Running openSUSE 10.2 -> bash 3.1.17(1)
 
Old 06-30-2007, 05:58 AM   #2
titopoquito
Senior Member
 
Registered: Jul 2004
Location: Lower Rhine region, Germany
Distribution: Slackware64 14.2 and current, SlackwareARM current
Posts: 1,644

Rep: Reputation: 145Reputation: 145
Your example works without a problem here, with or without spaces in the file names. Bash 3.2.15(2) on Slackware, rename from util-linux 2.12r.
 
Old 06-30-2007, 05:59 AM   #3
SciYro
Senior Member
 
Registered: Oct 2003
Location: hopefully not here
Distribution: Gentoo
Posts: 2,038

Rep: Reputation: 51
The problem: there are two seperate rename commands, one from perl, another more basic. The first example is the more basic rename command from util-linux i think, the second is for the perl version. So, the first question, what rename command do you have installed (as they are not compatible)?

Also, what do you mean by it dident work? Any error messages to show? And i assume are you already in the same directory as the files you want renamed.
 
Old 06-30-2007, 06:21 AM   #4
karnaf
Member
 
Registered: Dec 2005
Distribution: Linux Mint 14 (Cinnamon), Xubuntu 12.04, Ubuntu 10.04
Posts: 49

Original Poster
Rep: Reputation: 15
Using rename from util-linux-2.12r, so I guess we're dealing with the basic one.

Didn't work == no error msgs, just acting as if it has worked but no file changes made. Of course I'm in the directory and have permission to rename files there.

I've tried the more complex bash script
Code:
for OLD_FILE in *.MP3
do
  NEW_FILE=$(echo $OLD_FILE | tr '[:upper:]' '[:lower:]' | tr '[ ]+' '.')
  mv $OLD_FILE $NEW_FILE
done
Which throws errors for each file saying that $NEW_FILE is not a directory (???)

Cheers!
karnaf
 
Old 06-30-2007, 06:34 AM   #5
titopoquito
Senior Member
 
Registered: Jul 2004
Location: Lower Rhine region, Germany
Distribution: Slackware64 14.2 and current, SlackwareARM current
Posts: 1,644

Rep: Reputation: 145Reputation: 145
I don't know why it won't work for you, but another solution:

for file in *.MP3; do mv ${file} ${file//.MP3/.mp3}; done
 
Old 06-30-2007, 07:06 AM   #6
karnaf
Member
 
Registered: Dec 2005
Distribution: Linux Mint 14 (Cinnamon), Xubuntu 12.04, Ubuntu 10.04
Posts: 49

Original Poster
Rep: Reputation: 15
Code:
for file in *.MP3; do mv ${file} ${file//.MP3/.mp3}; done
Not working either, but it looks like the original file name has character which mess up the scripts (such as spaces and brackets)

I ended up editing my above script to do the job
Code:
for OLD_FILE in *.MP3
do
  NEW_FILE=$(echo $OLD_FILE | tr '[:upper:]' '[:lower:]' | tr '[ ]+' '.' | sed 's/(\(.*\))//g' | sed 's/[\.]\{1,\}/./g')
  mv "$OLD_FILE" "$NEW_FILE"
done
But I am still curious how come the simple 'rename' thing could not work...
 
  


Reply



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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to rename a partition akjmicro Linux - General 3 12-30-2005 01:59 PM
How can i Rename file? Khmer Linux - Newbie 4 10-21-2005 08:09 AM
How do I rename a file? Thaidog Linux - Newbie 5 10-10-2003 10:28 PM
rename workgroup nwilcox Linux - Networking 2 09-14-2003 12:31 AM
Rename my pc ? Tanc Linux - Newbie 6 09-13-2003 08:28 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 03:44 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration