Operating System - HP-UX
1834822 Members
2548 Online
110070 Solutions
New Discussion

Re: Convert upper case file names to lower case

 
SOLVED
Go to solution
Bruce Baillie
Regular Advisor

Convert upper case file names to lower case

Our file system for users has always been lower case and we want to keep it that way. Some users have begun using upper case. Now I need to search the users area of the file system and rename all upper case files to lower case.
mv FILE `echo FILE | tr "[:upper:]" "[:lower:]"`
I know I can use tr to do the renaming, but what would be a good way to find the files.
Why can't we all get along?
9 REPLIES 9
Bill McNAMARA_1
Honored Contributor

Re: Convert upper case file names to lower case

this is quick.. is there not an isupper function. You could use that in awk..
It works for me (tm)
James R. Ferguson
Acclaimed Contributor
Solution

Re: Convert upper case file names to lower case

Hi:

Try this:

# cd
# find . -xdev -type f -name "[[:upper:]]*"

This will list all files (not directories, since the 'find' specified only '-type f' that contain any uppercase characters in their names. You can do what you wish with the output.

Regards!

...JRF...
someone_4
Honored Contributor

Re: Convert upper case file names to lower case

Hi

If you want to find the files that are in a directory that that has lower case files mixed up with uppercase files this will work.

ls [A-Z]*


richard
curt larson_1
Honored Contributor

Re: Convert upper case file names to lower case

how about
typeset -l file
find . -type f |
while read File
do
file=$File
if [[ "$File" = "$file" ]] ;then
/usr/bin/true
else
mv $File $file
fi
done

of course this is only going to work if all
your directories are lowercase already
Darren Prior
Honored Contributor

Re: Convert upper case file names to lower case

Hi,

Just to be cautious I'd script this, and include a check to see if there's already a lower case version - otherwise it'll get overwritten.

regards,

Darren.
Calm down. It's only ones and zeros...
Mark Greene_1
Honored Contributor

Re: Convert upper case file names to lower case

Find is supposed to use the same regular expression compliance that tr does (see man find, man 5 regex). So, this form:

find . -name "[:upper:]" -type "f" -print

Should work, but I am getting mixed results on my 11.11 system. Ideally, you ought to be able to run this:

FILELIST=`find . -name "[:upper:]" -type "f" -print`
for FILENAME in `echo "$FILELIST"`; do
mv "$FILENAME" `echo "$FILENAME"|tr "[:upper:] "[:lower:]"`

and is should work. If it picks up a file that really is all lower case, it won't matter. Your bigger concern is ensuring it got all the upper case ones.

mark
the future will be a lot like now, only later
Mark Greene_1
Honored Contributor

Re: Convert upper case file names to lower case

Darren is absolutely correct, so ignore what I wrote about getting lowercase files. If you move a file to itself, you'll end-up with a zero byte file (i.e., empty) file.

Sorry for missing that.

mark
the future will be a lot like now, only later
curt larson_1
Honored Contributor

Re: Convert upper case file names to lower case

combining the find with a regular expression and a variable typeset to lowercase seems like a good way to go

typeset -l file

find . -xdev -type f -name "[:upper:]*" |
while read FILE
do
file="$FILE"
mv "$FILE" "$file"
done
Bruce Baillie
Regular Advisor

Re: Convert upper case file names to lower case

Thanks to James Ferguson, just what I was looking for. I will find all the files and creat a list for further processing.

find . -name "[[:upper:]]*" -print > list.txt
Why can't we all get along?