$ for i in `ls`; do mv $i `echo $i | tr [A-Z] [a-z]`; done
Of course, you need to be careful that there are no files that have
the same name regardless of case. The GNU mv can
be passed the -i flag that will make the program
prompt you before overwriting an existing file. If you want to
uppercase filenames, simply flip the arguments to
tr. You can even apply this to an entire branch of
a file system by sticking this in a find command.
First, create a small shell script that can downcase a file and call
it downcase:
#!/bin/sh
mv $1 `echo $1 | tr [A-Z] [a-z]`
Now you can really do some damage with find:
$ find /directory/to/be/affected -exec 'downcase' '{}' ';'
Obviously, running this programming on random directories as
root is not recomended, unless
you're looking to test your backup system.
% echo '[ ]' | tr '[a-z]' A
AA Berkeley version
% echo '[ ]' | tr '[a-z]' A
[ ] System V version
There's one place you don't have to
worry about the difference between the two versions: when
you're converting one range to another range, and
both ranges have the same number of characters. For example, this
command works in both versions:
$ tr '[A-Z]' '[a-z]' < file
both versions
The Berkeley tr will convert a
[ from the first string into the same character
[ in the second string, and the same for the
] characters. The System V version uses the
[ ] characters as range operators. In both
versions, you get what you want: the range A-Z is
converted to the corresponding range a-z. Again,
this trick works only when both ranges have the same number of
characters.
The System V version also has a nice feature: the syntax
[a*n],
where n is some digit, means that the
string should consist of n repetitions of
character "a." If
n isn't specified or is
0, it is taken to be some indefinitely large number. This is useful
if you don't know how many characters might be
included in the first string.