Showing results for 
Search instead for 
Do you mean 

change file name

SOLVED
Go to Solution
Regular Advisor

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
1 ACCEPTED SOLUTIONS
Highlighted
Honored Contributor Honored Contributor

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
5 REPLIES
Highlighted
Honored Contributor Honored Contributor

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
Esteemed Contributor Esteemed Contributor

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
Honored Contributor Honored Contributor

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!
Honored Contributor

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.
Honored Contributor Honored Contributor

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!