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?

4
  • You mention "bash" and "cmd", which are two different environments. Which one is it? I'm assuming Bash? Feb 15, 2010 at 0:59
  • By cmd I mean "command line" (terminal)
    – Kop
    Feb 15, 2010 at 1:02
  • Ah. cmd usually refers to the Windows command-prompt. Feb 15, 2010 at 1:36
  • 1
    Duplicate of: serverfault.com/questions/88442/… Feb 15, 2010 at 1:41

3 Answers 3

2

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

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.

2
  • This fails for files that have spaces in their names. Feb 15, 2010 at 1:38
  • This also fails for me if a subfolder contains capital letters.
    – Studer
    Feb 15, 2010 at 1:42
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