Uppercase to lowercase

Hello,

I have a list of files in a directory whose names are all in uppercasse, including the file format for eg *.MP3 . I would like to convert these to the normal way we write it ie ABC.MP3 to be converted to Abc.mp3 . I know that this can be done manually by using a lot of "mv" or rename operations, but is there any automated way to do it ? Like a shell script ?

Hi

ls *.MP3 | perl -lne 'rename $_,ucfirst(lc($_));'

OR
If you have GNU sed:

ls *.MP3 | sed 's/\(.*\)\.MP3/mv "&" "\L\u\1.mp3"/'  | sh

Guru.

Hello,

This worked, but only that the entire filename got converted to lowercase, I would like the first character to still be in uppercase.

perl -e '
chdir "/path/to/your/directory" or die "Cannot chdir ($!)\n";
for (<*.MP3>) {
 if(-f) {
  $old=$_;
  $new=ucfirst lc $old;
  print "Renaming $old to $new\n";
  #print "Renaming $old to $new unsuccessful ($!)\n" unless rename $old => $new;
 }
}'

Uncomment the rename line if the printed lines seem OK.

Hello,

guruprasadpr s shell script worked , thank you ,

You can do it first letter capitalization easily from within Bash.

For example:

FirstCap()
{
   lower=${1,,}
   echo ${lower^}
}

ls -1 *.MP3  |  while read filename
do
      FirstCap  $filename
done
1 Like

These require bash4.

First, -1 is not necessary since the output of ls is not going to a terminal.

Second, ls is not necessary:

for filename in *.MP3