LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
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 01-29-2013, 10:13 AM   #1
lghizoni
Member
 
Registered: Dec 2011
Location: Brazil
Distribution: Ubuntu
Posts: 100

Rep: Reputation: Disabled
rename multiple files


Hello all,

I have 638 files, and I would like to rename them, but just substitue 'M' to 'R' in all od them. Teh file are named as follows:

WFI_FM2_DB_OD_B13_G100_I25_20121213_M_1.TXT

All the files are named like this one above, and I just want to substitue 'M' to 'R' in all of them.

Thanks a lot.
 
Old 01-29-2013, 11:24 AM   #2
thesnow
Member
 
Registered: Nov 2010
Location: Minneapolis, MN
Distribution: Ubuntu, Red Hat, Mint
Posts: 170

Rep: Reputation: 56
Do you mean all occurrences of M within the file name or just some of them (like the _M_ at the end)?
 
Old 01-29-2013, 12:38 PM   #3
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,492

Rep: Reputation: 2092Reputation: 2092Reputation: 2092Reputation: 2092Reputation: 2092Reputation: 2092Reputation: 2092Reputation: 2092Reputation: 2092Reputation: 2092Reputation: 2092
If you want to replace all M with R, then:
Code:
for i in *.TXT; do echo mv "$i" "${i//M/R}"; done
Of course you might need to swap out the "*.TXT" globbing pattern to whatever is necessary to match your files. Once you verify that the renaming is correct (based on the output of the script), then remove the "echo" in the script to actually do the renaming.
 
Old 01-29-2013, 01:08 PM   #4
lghizoni
Member
 
Registered: Dec 2011
Location: Brazil
Distribution: Ubuntu
Posts: 100

Original Poster
Rep: Reputation: Disabled
Just the last M (_M_)!
 
Old 01-29-2013, 01:09 PM   #5
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,492

Rep: Reputation: 2092Reputation: 2092Reputation: 2092Reputation: 2092Reputation: 2092Reputation: 2092Reputation: 2092Reputation: 2092Reputation: 2092Reputation: 2092Reputation: 2092
Quote:
Originally Posted by lghizoni View Post
Just the last M (_M_)!
In that case:
Code:
for i in *.TXT; do echo mv "$i" "${i/%_M_1.TXT/_R_1.TXT}"; done
 
Old 01-30-2013, 04:03 AM   #6
lghizoni
Member
 
Registered: Dec 2011
Location: Brazil
Distribution: Ubuntu
Posts: 100

Original Poster
Rep: Reputation: Disabled
Well, I'm running your command, and it gets no error, but the filenames keep the same.

Thanks.
 
Old 01-30-2013, 04:10 AM   #7
lghizoni
Member
 
Registered: Dec 2011
Location: Brazil
Distribution: Ubuntu
Posts: 100

Original Poster
Rep: Reputation: Disabled
I've search for the rename command, and it worked now!

rename 's/\_M_1.TXT/\_R_1.TXT/' *_M_1.TXT

Thanks a lot anyway!!

Do you know where could I get to learn more about these commands?

Cheers.
 
Old 01-30-2013, 08:48 AM   #8
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,492

Rep: Reputation: 2092Reputation: 2092Reputation: 2092Reputation: 2092Reputation: 2092Reputation: 2092Reputation: 2092Reputation: 2092Reputation: 2092Reputation: 2092Reputation: 2092
Quote:
Originally Posted by lghizoni View Post
Well, I'm running your command, and it gets no error, but the filenames keep the same.

Thanks.
As I mentioned in my original post:
Quote:
Once you verify that the renaming is correct (based on the output of the script), then remove the "echo" in the script to actually do the renaming.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Yet another Rename multiple files thread grebois Linux - Newbie 4 10-30-2012 08:38 PM
[SOLVED] rename multiple files at a time biki_happy Linux - Newbie 8 08-23-2012 08:19 AM
Rename multiple files L1nuxn00b703 Linux - Newbie 4 04-11-2012 02:30 AM
rename multiple files tjay1983 Programming 3 08-10-2010 12:43 AM
How to rename multiple files? Rostfrei Linux - Newbie 3 07-11-2006 06:06 AM


All times are GMT -5. The time now is 09:15 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration