[mdlug] Hideous script for recursively renaming a directory tree to lower case

Jeff Hanson jhansonxi at gmail.com
Tue Feb 5 18:02:02 EST 2008


On Feb 4, 2008 4:27 PM, Aaron Kulkis <akulkis3 at hotpop.com> wrote:
> You didn't take advantage of the find command:
>
> I would approach it like this:
>
>
> #!/bin/bash
> # recursively rename files and directories by translating
> # upper case letters to lower case.
> #
> # Note -- beware of filename collisions when updating with
> # files from microsoft platforms:
> #
> # 1.  Run once to convert all files to lowercase BEFORE
> #     installing update files
> #
> # 2. Install updated MS-platform files
> #
> # 3. Run again, in event of name collision,
> #     new files will overwrite older files
> #
> #
> #
> # usage:  scriptname
> #
> # No arguments... operates on the contents of the current directory
> #
> # Date          Author                  Action
> # ------------  ----------------------- ---------------------------
> # 04 Feb 2008   Aaron R. Kulkis         0.1 Code (untested)
>
>
> filetolower()
> { FILENAME=$1
>    NEWFILENAME=`echo $FILENAME | tr [:upper:] [:lower:] `
>    mv $FILENAME $NEWFILENAME
> }
>
> find . -print -exec  filetolower \{\}\;

Thanks for the tip.  I need to start using functions more in my
scripts.  It hasn't been a major problem yet due to my script
structures but it would help readability if I planned for it in
advance.



More information about the mdlug mailing list