1819857 Members
3148 Online
109607 Solutions
New Discussion юеВ

change file names

 
SOLVED
Go to solution
Brian Lee_4
Regular Advisor

change file names

I have 100 files starting with sla in one directory.
I want to change those files starting with sap.

How can I do it?
brian lee
5 REPLIES 5
Mark Grant
Honored Contributor
Solution

Re: change file names

Somthing like

for i in 'ls sla*'
do
$base=`expr "$i" : "sla\(.*\)"`
mv $i "sap$base"
done

Test this first using "cp" instead of "mv" if you're nervous :)
Never preceed any demonstration with anything more predictive than "watch this"
John Poff
Honored Contributor

Re: change file names

Hi,

Here is one way to do it:

for f in sla*
do
t=sap${f#sla}
mv $f $t
done


JP
Michael Schulte zur Sur
Honored Contributor

Re: change file names

Hi Brian,

for FILE in sla*
do
NEWFILE=`expr "${FILE}" : "sla\(.*\)"
mv ${FILE} "sap${NEWFILE}"
done

greetings,

Michael
Mark Greene_1
Honored Contributor

Re: change file names

cd to the directory and run this:

for _FILE in `ls ./sla*`; do
_NEW_FILE=`echo $_FILE|sed -e s/sla/sap/`
mv $_FILE _NEW_FILE
done

the future will be a lot like now, only later
Jean-Luc Oudart
Honored Contributor

Re: change file names

#!/bin/sh

or fln in `ls sla*`
do
newfln=$(echo $fln | cut -c4-)
newfln="sap"${newfln}
echo $fln $newfln
done

change echo with mv
you may want to check file existence beforehand

Regards,
Jean-Luc
fiat lux