Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Change file name from upper to lower case (See related posts)

This script requires perl, and a modern shell with ls (this was written/tested using Bash). It also will not work recursively without some modifications.

for file in `ls -1|perl -ne 'print "$_" if (/[A-Z]/);'`
do
  mv ${file} `echo ${file}|perl -ne 'chomp;print "$_" if (tr/A-Z/a-z/);'`;
done

Comments on this post

jim posts on Feb 04, 2006 at 00:31
If you have perl intalled, you probably have rename installed:

rename 'y/A-Z/a-z/' *

camcorder posts on Mar 23, 2006 at 09:45
Another one liner without using perl might be:
for i in *; do mv $i `echo $i | tr [:upper:] [:lower:]`; done

if you have lower case files this script will put a warning for them stating target file is same, but it's just a warning, that would change all files to lowercase.

You need to create an account or log in to post comments to this site.


Click here to browse all 4861 code snippets

Related Posts