UNIX command to make files LOWERCASE???

pwharff

Registered
Does anyone know of a command or program that will allow you to change the case of any file/files to lowercase???

PLEASE HELP ASAP, I really don't feel like changing over 200 files to lowercase! :) Thanks in advance!!!

--Paul
 
While I don't have a solution, I was wondering something. Just out of curiosity, why do you need to do this?
 
I maintain the server for our company and on that server we have a Java application that allows our clients to create and maintain websites through templates online. This Java application automatically changes the case of the files when uploaded but only allows the user to upload 5 files at once. Since I have direct access to the server, I uploaded about 200 HTML files to the server for one of our clients, but now the Java application doesn't recognize the files because of being lowercase. I had this problem before but there was only about 20 files to change so I changed them manually, after I had done this, our Java app recognized all the HTML files. So I know that is what I need to do here.

Please someone help!!!
 
For csh/tcsh:
Code:
foreach filename (*)
set newname=`echo $filename | tr '[:upper:]' '[:lower:]'`
mv $filename $newname
end

For sh/ksh/zsh/bash:
Code:
for filename in *; do
newname=`echo $filename | tr '[:upper:]' '[:lower:]'`
mv $filename $newname
done

If this is something you'll do regularly, first add
Code:
#!/bin/sh
to a file, then append the second set of commands. Call the file something like tolower.sh, and chmod a+x tolower.sh it to make it executable.

Note these will lowercase ALL files in your current directory; change the (*) (for csh) or in * (sh) to match more specifically if necessary.
 
Perl (to be written into a file, like the previous scripts):

Code:
#!/usr/bin/perl -w
use strict;

my (@files, $filename);
@files = glob "*"; # Change to match fewer files if desired
foreach $filename (@files)
{
  # Skip the two special files (don't know how the rename
  # would affect these...)
  next if ($filename eq '.') || ($filename eq '..');
  rename $filename, lc($filename);
}

Save to file (like tolower.pl), run chmod +x tolower.pl, to execute type in tolower.pl in the desired directory.

BTW, the chmod a+x filename is the same as chmod +x filename.
 
BTW, the Perl code is untested -- but it's simple so I doubt there would be any problems.

And it could also be more obfuscated (as a one-liner form the command line):
Code:
perl -e 'foreach $file (glob "*") { rename $file, lc($file) }'

And I just tested the one liner...
 
Did you want to change the contents of the file, or the name? To do the contents, you could

cat mixedcasefile | tr "[:upper:]" "[:lower:]" > lowercasefile
 
Thank you guys so much. I changed the case and now all the pages work correctly!!!

Do any of you guys have a good resource or know of a good book for shell scripting???

Thanks again!!!
 
... also, there's a book by those ppl that do "The Complete Referece" series ... its not one of the "complete" references, but its called something like "Programming Linux" ... it's a great reference book - but possibly not such a good learning book, unless you like *very* concise programming literature ;-)

(just checked Amazon - its Mc Graw Hill/Osborne who do the book)
(and I just checked their site: the book's called "Linux Programmer's Reference")
(could have re-written the post, but couldn't be arsed ;-))

C
 
Back
Top