Operating System - HP-UX
1833776 Members
2274 Online
110063 Solutions
New Discussion

rename files to the same name but with lowercase

 
SOLVED
Go to solution
Salvador Reyna
Advisor

rename files to the same name but with lowercase

Hi, I'm trying to convert the files in lowercase.
f.e:./folder/FILe1.tXT
./folder/fiLE2.TXT

I'm trying with "awk", I'm trying with "tr".

Somebody told me ..."with LINUX anything is imposible"..... I'm not sure :-((

Could you help me, please?
14 REPLIES 14
Jean-Luc Oudart
Honored Contributor

Re: rename files to the same name but with lowercase

try this

F1="./folder/FILe1.tXT" # or whatever
NEWNAME=$(echo $F1 | tr '[A-Z]' '[a-z]')
mv $F1 $NEWNAME

Regards
Jean-Luc
fiat lux
curt larson_1
Honored Contributor

Re: rename files to the same name but with lowercase

if your using a posix style shell:

typeset -l newFileName

filename=ABC
newFileName=$filename

print $filename $newFileName
curt larson_1
Honored Contributor

Re: rename files to the same name but with lowercase

and with awk

fileName=ABC
print $fileName | awk '{print tolower($0);}'
Alan Meyer_4
Respected Contributor

Re: rename files to the same name but with lowercase

Be sure to check to see if the new(lowercase) file name does NOT already exist
if [ -f "newfile.txt" ] ;then
... modify name here ...
fi
" I may not be certified, but I am certifiable... "
Jose Mosquera
Honored Contributor

Re: rename files to the same name but with lowercase

Hi,

I'm not sure about your question, in any case pls try this:

for FILE in `ls -d *`
do
FILE_CAP=`echo $FILE|awk '{ print tolower ($1) }'`
mv FILE FILE_CAP
done

Saludos
Jose Mosquera
Honored Contributor
Solution

Re: rename files to the same name but with lowercase

Oooopss..!

The correct sintax must be:
for FILE in `ls -d *`
do
FILE_CAP=`echo $FILE|awk '{ print tolower ($1) }'`
mv $FILE $FILE_CAP
done

rgds again
Bill Hassell
Honored Contributor

Re: rename files to the same name but with lowercase

The tr man page gives you the details:

cd /some_folder/

for MYFILE in $(echo * .[!*]}
do
LOWERCASE=$(echo $MYFILE | tr -s '[:upper:]' '[:lower:]')


if [ -a $LOWERCASE ]
then
echo "\nFile $LOWERCASE already exists, cannot rename $MYFILE\n"
else
mv $MYFILE $LOWERCASE
done


Notice the test for a duplicate just in case you have two separate files such as: File1 and FILE1 which will be duplicates when changed to lowercase.


Bill Hassell, sysadmin
Salvador Reyna
Advisor

Re: rename files to the same name but with lowercase

Well, i'm not sure if i've explained fine my problem.

I have some files in a folder.
File1.txT ,FILe2.Txt,fILe3.TXT

I need that all these files become in lowercase, but not one by one; all in the same time.

Like that: file1.txt,file2.txt,file3.txt

Thanks a lot
Jose Mosquera
Honored Contributor

Re: rename files to the same name but with lowercase

Hi again,

All of them at once..! uummmhhh, is relative point of view, pls try my last suggestion, this move file by file in an unique cicle.

Saludos.
James R. Ferguson
Acclaimed Contributor

Re: rename files to the same name but with lowercase

Hi Salvador:

You could do something like:

# cd /folder
# perl -e 'for $x (@ARGV) {$y=$x;$y=~s/($x)/\L\1/g;rename $x,$y}' FILe1.tXT fiLE2.TXT

This will rename files of mixed upper and lower case as specified by the argument list, to filenames consisting of only lowercase letters.

Regards!

...JRF...

Alessandro Pilati
Esteemed Contributor

Re: rename files to the same name but with lowercase

Salvador,
take this 1-line command that converts your files altogether:

find . -type f|awk '{print $1,tolower($1)}'|xargs -n2 mv 2>/dev/null

Good luck,
Alex
if you don't try, you'll never know if you are able to
Alessandro Pilati
Esteemed Contributor

Re: rename files to the same name but with lowercase

Obiovusly launch the command after you did a "cd " where the files to convert are present.

Regards,
Alex
if you don't try, you'll never know if you are able to
Salvador Reyna
Advisor

Re: rename files to the same name but with lowercase

YEAH!!

GREAT !... THANKS A LOT for everybody.

Jose Maria, I didn't see your update. In your third comment I saw the right version.

THANKS & REGARDS
Salvador Reyna
Advisor

Re: rename files to the same name but with lowercase

THANKS FOR ALL