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 |
for x in *.cfg-sample
do mv $x `echo $x | sed s/cfg-sample/cfg/g` done I just tried it and it works. |
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 |
I see some are typing quicker then me ;)
We used the same trick so must be the right one... |
Some around here are just so eager to help. :D
|
your best people. Its works...thanks a lot
|
All times are GMT -5. The time now is 03:01 PM. |