LinuxQuestions.org
Visit Jeremy's Blog.
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 10-12-2004, 02:26 PM   #1
suresheva31
LQ Newbie
 
Registered: Oct 2004
Posts: 25

Rep: Reputation: 15
How do I rename a lot of files at once?


Hey guys,

I want to rename my whole bunch of files has extension of .cfg-sample to .cfg at once

Examples:

checkcommands.cfg-sample escalations.cfg-sample nagios.cfg-sample

to

checkcommands.cfg escalations.cfg nagios.cfg

this is the script that i found from the this website: onlamp.com/pub/a/onlamp/2002/09/05/nagios.html?page=2



for i in *cfg-sample; do mv $i
`echo $i | sed -e s/cfg-sample/cfg/`; done;

it doesn't seems working for me, and i get the following error.

mv: missing file argument
Try `mv --help' for more information.
-bash: cgi.cfg: command not found
mv: missing file argument
Try `mv --help' for more information.
-bash: checkcommands.cfg: command not found


any helps, thanks in advance

suresh
 
Old 10-12-2004, 02:43 PM   #2
vasudevadas
Member
 
Registered: Jul 2003
Location: Bedford, UK
Distribution: Slackware 11.0, LFS 6.1
Posts: 519

Rep: Reputation: 30
for x in *.cfg-sample
do
mv $x `echo $x | sed s/cfg-sample/cfg/g`
done

I just tried it and it works.
 
Old 10-12-2004, 02:45 PM   #3
jeickal
Member
 
Registered: Oct 2004
Distribution: Mandrake, DSL, SuSE, RedHat
Posts: 71

Rep: Reputation: 15
How about this one (from bash):

- 1st, get all you file names in a tempfile like this:

ls -1 *.cfg-sample > tempfile

Note: the "-1" option to get one file per line

- then run this loop:


while read a
do
mv $a `echo $a|sed -e "s\cfg-sample\cfg\g"`
done < tempfile


Carefull to respect the quote " and `
This will read "tempfile" containing your file names line by line and store each line in the variable "a" each time it loops

then you move $a into itself but replacing "cfg-sample" by cfg thanks to the sed command.
Hope this help
 
Old 10-12-2004, 02:48 PM   #4
jeickal
Member
 
Registered: Oct 2004
Distribution: Mandrake, DSL, SuSE, RedHat
Posts: 71

Rep: Reputation: 15
Wink

I see some are typing quicker then me

We used the same trick so must be the right one...
 
Old 10-12-2004, 02:49 PM   #5
vasudevadas
Member
 
Registered: Jul 2003
Location: Bedford, UK
Distribution: Slackware 11.0, LFS 6.1
Posts: 519

Rep: Reputation: 30
Some around here are just so eager to help.
 
Old 10-12-2004, 02:57 PM   #6
suresheva31
LQ Newbie
 
Registered: Oct 2004
Posts: 25

Original Poster
Rep: Reputation: 15
your best people. Its works...thanks a lot
 
  


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



Similar Threads
Thread Thread Starter Forum Replies Last Post
How can I rename a lot of files with a single command? pujolasdf Linux - Software 4 07-20-2005 05:27 AM
rename files allelopath Linux - General 5 07-05-2005 03:00 AM
remove a lot of files matko Linux - General 1 07-08-2004 03:33 AM
Can not rename files. Maximus2000 Linux - General 0 04-22-2004 01:36 PM
A LOT of files NetScripter Linux - General 3 08-22-2003 12:54 PM

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

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