DZone 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

Snippets has posted 5883 posts at DZone. View Full User Profile

Change File Name From Upper To Lower Case

  • submit to reddit
        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]/);'`
  mv ${file} `echo ${file}|perl -ne 'chomp;print "$_" if (tr/A-Z/a-z/);'`;


Snippets Manager replied on Thu, 2006/03/23 - 9:31am

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.

Snippets Manager replied on Sun, 2006/01/22 - 11:40pm

If you have perl intalled, you probably have rename installed: rename 'y/A-Z/a-z/' *