LinuxQuestions.org
Review your favorite Linux distribution.
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 05-16-2007, 04:24 PM   #1
rogueeve
LQ Newbie
 
Registered: Oct 2006
Posts: 11

Rep: Reputation: 0
How to rename multiple files with the same extension


How do you rename multiple files with the same prefix but different extensions to have a new prefix?

For example say I have tcpserver.c, tcpserver.h & tcpserver.fdh and want to drop the "server" from their names.

Under DOS I can do:

ren tcpserver.* tcp.*


What is the equivalent command under unix? Obviously mv tcpserver.* tcp.* does not do as intended.
 
Old 05-16-2007, 04:40 PM   #2
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Debian sid + kde 3.5 & 4.4
Posts: 6,823

Rep: Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946
Use the rename command:

rename 's/tcpserver/tcp/' tcpserver.*
 
Old 05-16-2007, 10:53 PM   #3
rogueeve
LQ Newbie
 
Registered: Oct 2006
Posts: 11

Original Poster
Rep: Reputation: 0
Thumbs up

That did not work, it returned to the shell prompt with no errors but the filenames were not changed.

But, I was able to get it work by typing rename tcpserver tcp tcpserver.*

I made a shell script /usr/bin/rene:

rename $1 $2 $1.*

Now next time I can just type rename tcpserver tcp.


Thanks
 
Old 05-18-2007, 01:54 AM   #4
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Debian sid + kde 3.5 & 4.4
Posts: 6,823

Rep: Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946Reputation: 1946
That's interesting. My rename won't let me do it your way. I always get a "bareword not allowed" error. I HAVE to use the s/1/2/ pattern.

Different distros sometimes use different programs with the same name and function though, so I guess it's not too surprising.
 
  


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
Help with Bash Script - Rename Multiple Files embsupafly Programming 16 04-02-2010 03:50 AM
Rename multiple files in folders??? adds2one Linux - Software 19 10-05-2006 12:22 AM
How to rename multiple files? Rostfrei Linux - Newbie 3 07-11-2006 06:06 AM
Changing extension of multiple files harisund Programming 17 06-01-2006 10:59 AM
changing extension of multiple files shaggystyle Linux - General 5 01-29-2004 12:35 PM


All times are GMT -5. The time now is 07:33 PM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration