Re: change file name (10 Views)
Reply
Regular Advisor
hangyu
Posts: 244
Registered: ‎06-21-2005
Message 1 of 6 (10 Views)
Accepted Solution

change file name

I have many files that its file name are block letter ( eg .ABC ) , I want to change all these files to small letter ( eg. abc ) , could suggest what can I do ? thx
Please use plain text.
Honored Contributor
Andreas Voss
Posts: 1,364
Registered: ‎10-14-1997
Message 2 of 6 (10 Views)

Re: change file name

Hi,

here's what you need:

for file in $(ls)
do
mv $file $(echo $file|tr "[A-Z]" "[a-z]")
done

Regards
Please use plain text.
Esteemed Contributor
Alessandro Pilati
Posts: 355
Registered: ‎06-30-2005
Message 3 of 6 (10 Views)

Re: change file name

Hangyu,
use this script giving as uniqe argument the directory where you have the file to convert in lowercase:

ls -1 $1|while read a
do
upper=$a
lower=$a
typeset -l lower
mv $1/$upper $1/$lower
done

Regards,
Alex
if you don't try, you'll never know if you are able to
Please use plain text.
Honored Contributor
Muthukumar_5
Posts: 4,030
Registered: ‎06-09-2004
Message 4 of 6 (10 Views)

Re: change file name

You can do it as,

cd
for file in `ls`
do

mv $file $(echo $file | tr '[A-Z]' '[a-z]')

done



Easy to suggest when don't know about the problem!
Please use plain text.
Honored Contributor
Ninad_1
Posts: 990
Registered: ‎05-22-2002
Message 5 of 6 (10 Views)

Re: change file name

Hi,

Please use following command
2 approaches:
I) If all the files in that dir are to be checked if they are in block letters and if yes convert to small letters then -

goto the directory where these files are and then
for i in `ls -1`
do
echo $i | tr -s '[:upper:]' '[:lower:]' | xargs mv $i
done

This will give u errors for files that are already in small letters - just ignore that.
One important thing here is that if there is already a file with same name in small letters the file will be overwritten.

II>
You can write the filenames which you want to convert into a file - sya files.list and then
for i in `cat files.list`
do
echo $i | tr -s '[:upper:]' '[:lower:]' | xargs mv $i
done



Hpe this helps.
Please use plain text.
Honored Contributor
Muthukumar_5
Posts: 4,030
Registered: ‎06-09-2004
Message 6 of 6 (10 Views)

Re: change file name

You can do with another method as,

# ls -c1 | awk '{ print "mv ",$1,tolower($1); }' | ksh

hth.
Easy to suggest when don't know about the problem!
Please use plain text.
The opinions expressed above are the personal opinions of the authors, not of HP. By using this site, you accept the Terms of Use and Rules of Participation