Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Changing filenames from upper to lower case.

Status
Not open for further replies.

scfc1976

Programmer
May 19, 2009
12
GB
Hi all,

I have been looking at various threads in relation to this and haven't been able to get the right result. The closest I have got was to turn all uppercase characters within a file to lowercase.

What I need is to change the filename of various files (the amount of which can change at any given bootup).

Example file listing within directory:

AAAAAAAAAAA.txt
BBBBBBBBBBB.txt
CCCCCCCCCCC.txt
DDDDDDDD.txt
EEEEEEEEEEEEEEEEE.txt

I have tried the following which changed the contents of the file.

cat AAAAAAAAAAA.txt | tr '[:upper:]' '[:lower:]'

I'm sure this can't be as difficult as I am making it.

Thanks

scfc1976.
 
You may try this:
Code:
ls | awk '$0!=tolower($0){printf "mv \"%s\" \"%s\"\n",$0,tolower($0)}' | sh

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
OOps.
Code:
ls | awk '$0!=tolower($0){printf "mv \"%s\" \"%s\"\n",$0,tolower($0)}' | sh

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Thanks for the response. I kept getting syntax errors,
(probably due to seat to keyboard interface), however I mangaed to sort the problem after a bit of a lay off.

My code was:-

#! /bin/sh


cd /home

for file in *
do

if [ -f $file ]
then
ucfile=`echo $file | tr '[:upper:]' '[:lower:]'`
if [ $file != $ucfile ]
then
mv -i $file $ucfile
fi
fi
done

Thanks again.
 
OK, just a strange name for a variable (ucfile) that holds a lowercase (lc) filename ... ;-)


HTH,

p5wizard
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top