Pages

Sunday, December 8, 2013

Linux Shell script to rename files from CAPS to small letters

This is a small script to rename multiple files from CAPITAL to small letters. Ok, why we require to do this? Recently we bought a new cam which is naming all photos in capital and it is very much difficult for me to change extension of these photos from caps to small to re-size/modify photos using mogrify Linux tool.

#!/bin/bash
#Author: Surendra Anne
for j in *
do
COUNT=$(ls -1 | wc -l)
if [ $j == $(basename $0) ]
then
echo "can not move  the script file which is running this"
else
org_file=$j
new_file=$(echo $j | tr [A-Z] [a-z])
echo "Moving $org_file --> $new_file"
mv $org_file $new_file
fi
done

Comment if there is any issue with this script.

1 comment:

  1. Hello sir,

    I think there is a typo in your code. I mean after do COUNT=$(ls-1****

    It is ls -l, right ?

    ReplyDelete