0

Possible Duplicate:
How can I recursively change the case of files and folders under bash

How can I convert all file names to lowercase in a directory and its subdirectories, using a command or batch script?

3 Answers3

2

If you also want to rename the folder, use this script.

Studer
  • 1,340
  • 9
  • 16
1

First off, tr can be used to translate text. tr [:upper:] [:lower:] will translate all upper case characters from stdin into lower case in stdout. So it's just a matter of working that into your script...

for $FILE in `find . -name [whatever] -print`
    do mv $FILE `echo $FILE | tr [:upper:] [:lower:]`
done

This is pretty ugly, and it spits out errors if the file name is already lower case. (because you try to move it onto itself) But it should do the job. Be sure to mod up whomever posts a cleaned up version.

Christopher Karel
  • 6,442
  • 1
  • 26
  • 34
1

This is mild variation to Christopher's answer,

find . -type f > files.txt
IFS="
";
for f in $(cat files.txt);
do
    mv $f $(echo $f | tr [:upper:] [:lower:])
done

If you want to work on directories rather than files use,

find . -type d > dirs.txt
nik
  • 7,040
  • 2
  • 24
  • 30