LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   Renaming All Caps Filename Into Lower Case (https://www.linuxquestions.org/questions/linux-general-1/renaming-all-caps-filename-into-lower-case-329865/)

slpwkr 06-03-2005 05:21 AM

Renaming All Caps Filename Into Lower Case
 
HIgh guuys I have this folder that consist all caps filename like:

INDEX.HTML
MEMBERS.HTML
CONFIRM.HTML
SUB.HTML
ALL.HTML

ETC..


Its too many to manually rename each file. Is there a linux command to convert all caps filename into a lowercase?

Thank You.

trevelluk 06-03-2005 05:39 AM

I don't know of any builtins to do this, but you could probably do this with a little shell script:

Code:

#!/bin/bash

for oldname in `ls`; do
    # tr translates characters from the first set specified to the corresponding character in the second set
    #in this case uppercase to lowercase
    newname=`echo $oldname | tr [:upper:] [:lower:]`
    mv oldname newname
done

I haven't tested this, but I think it should work (I advise you test with non-critical data first though).

slpwkr 06-03-2005 06:05 AM

How should I run the script its should be ./scriptname.sh right? where is the old filen name and the new filename? Anyway, I think the script is good only for few files to be renamed coz it is specific to which file? What if there is a hundred to be renamed? Thanks you

trevelluk 06-03-2005 06:23 AM

To run the script it's just ./filename
You only need the .sh if you actually saved the script file with the extension .sh

Ah, I've just noticed a mistake. The mv line should in fact read mv $oldname $newname

(edit)Just one more thing, this won't work on case-insensitive filesystems (e.g. vfat).


All times are GMT -5. The time now is 08:50 AM.