[olug] Unix Tip: FILNAMES UPPER TO LOWER

Jay Hannah jay at jays.net
Fri May 2 12:46:08 UTC 2003


Unix Guru Universe wrote:
> FILNAMES UPPER TO LOWER
> 
> This script can be used to
> renames all the file in
> current directory with
> UPPERCASE letters to lowercase.
> 
> I uses it because some time when
> I try to upload some files from
> a Windows system to a unix based
> web server, the files somehow gets
> converted to UPPERCASES, which is
> undesirable.
> 
> ###########################
> 
> for uppercase in `ls`
> do
>   for lowercase in `ls $uppercase|tr [A-Z] [a-z]`
>   do
>      mv $lowercase $uppercase 2>/dev/null
>   done
> done
> 
> ############################


Or from the command line via Perl:

[jhannah at gambit]$ ls
A  B  C  d
[jhannah at gambit]$ perl -e 'foreach (`ls`) { chomp; rename $_, lc($_) }'
[jhannah at gambit]$ ls
a  b  c  d

(Yes, I write real programs in Perl too, but command-line one-liners are
fun. -grin-)

Cheers,

Jay Hannah
Omaha Perl Mongers: http://omaha.pm.org


More information about the OLUG mailing list