Write a korn shell script for renaming the filenames of the files stored in a folder to lower case.

Questions by renjiraj

Showing Answers 1 - 12 of 12 Answers

amitmittal

  • Nov 29th, 2007
 

folder=$1

list_of_files=`ls $folder`

for file in $list_of_files;
do
        mv $file `echo $file | tr [:upper:] [:lower:]`
done;

  Was this answer useful?  Yes

ENIAC

  • Feb 18th, 2009
 

It picks up directory names inside the folder and renames them.
I'll be building a proper KSH version soon enough.  Stay tuned.

  Was this answer useful?  Yes

ENIAC

  • Feb 23rd, 2009
 

#!/bin/gawk -f
#
# LowerFiles.gawk
#
# Using GAWK, we can strip off the file name from the full path,
#    and rename it only when necessary (skip files that are already lowercase.)
# Usage example
#
#     find . -type f -print | ./LowerFiles.gawk | ksh
#
#  If you skip the 'ksh' portion, you can get a dry run
#  of the command output or redirect
#

BEGIN {
  FS="/";
}
{
if ( $NF ~ /[ABCDEFGHIJKLMNOPQRSTUVWXYZ]/ ) {
        printf "mv "$0" ";
        for (i=1; i<NF; i++) {
                printf $i"/";
        }

        printf tolower($NF);
        printf "n";
}
}

  Was this answer useful?  Yes

Rohit_Ash

  • May 27th, 2009
 

Tested script.

#! /usr/bin/ksh
echo "start"
for name in `ls -1`
do
echo "name $name"
name1=`echo $name | tr [A-Z] [a-z]`;
echo "name1 $name1"
mv $name $name1;
if [ -z $name ]
then
exit;
fi
done

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions