LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 11-17-2004, 09:29 AM   #1
Tuttle
Senior Member
 
Registered: Jul 2003
Location: Wellington, NZ
Distribution: mainly slackware
Posts: 1,291

Rep: Reputation: 52
Renaming lots of files


I have a folder full of files which I want to rename. The format I want is for every word to Begin with a capital letter and for the extentions to be lowercase eg:

the wallys - bad song.MP3

becomes:

The Wallys - Bad Song.mp3

Also, some of the names have underscores and I would like to replace these with spaces. Windows 98 is so bad with filenames!!

edit: the question is - can I do it with a simple(ish) command?

Last edited by Tuttle; 11-17-2004 at 09:32 AM.
 
Old 11-17-2004, 10:29 AM   #2
sgood1971
Member
 
Registered: Oct 2003
Distribution: Ubuntu 4.10
Posts: 30

Rep: Reputation: 15
You can try Mass Rename which I use and like. There are several programs on this search page including one called Cantus which is specific for .mp3 files.

Last edited by sgood1971; 11-17-2004 at 10:30 AM.
 
Old 11-17-2004, 01:58 PM   #3
ahh
Member
 
Registered: May 2004
Location: UK
Distribution: Gentoo
Posts: 293

Rep: Reputation: 31
You can run the following in the directory containing the files you want to rename.
Code:
for i in "$(ls ./)"; do if [ -f "$i" ]; then new_name=$(echo "$i" | tr "[:upper:]" "[:lower:]" | tr "_" " " | sed -e 's/^./\u&/' -e 's/ ./\U&/g'); fi; mv "$i" "$new_name"; done
It may be prudent to test it in a temporary directory first though

Oops, spotted a small problem, got to go to work now though so I'll fix it tomorrow - unless someone beats me to it.

Last edited by ahh; 11-17-2004 at 02:32 PM.
 
Old 11-17-2004, 02:49 PM   #4
ahh
Member
 
Registered: May 2004
Location: UK
Distribution: Gentoo
Posts: 293

Rep: Reputation: 31
Got it!
Code:
for i in $(ls ./ | tr " " "="); do j=$(echo $i | tr "=" " "); if [ -f "$j" ]; then new_name=$(echo "$j" | tr "[:upper:]_" "[:lower:] " | sed -e's/^./\u&/' -e 's/ ./\U&/g'); fi; mv "$j" "$new_name"; done
It should work provided you dont have a "=" in the file name. If you do change it for any character that is not in any file name.
 
Old 11-18-2004, 11:15 AM   #5
Tuttle
Senior Member
 
Registered: Jul 2003
Location: Wellington, NZ
Distribution: mainly slackware
Posts: 1,291

Original Poster
Rep: Reputation: 52
Thanks for the replies!
especially yours ahh, I know a lot of commands now and love to see the nuts and bolts of a command and how to apply it.
"mass rename" also looks good, I'll get it as well to see how it works :~]
 
  


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



Similar Threads
Thread Thread Starter Forum Replies Last Post
Renaming multple files.... maginotjr Slackware 4 06-04-2006 10:09 AM
bash help renaming files kahn Programming 6 06-16-2005 07:15 AM
renaming files script. xushi Programming 4 10-10-2004 08:06 AM
Renaming files as they are uploaded Cr4wford Linux - Software 1 04-26-2004 03:41 PM
Renaming files in one go saurya_s Linux - Software 1 01-12-2004 01:16 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 02:56 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