iSelfSchooling.com  Since 1999     References  |  Search more  | Oracle Syntax  | Free Online Oracle Training

    Home      .Services     Login       Start Learning     Certification      .                 .Share your BELIEF(s)...

 

. Online Accounting        .Copyright & User Agreement   |
    .Vision      .Biography     .Acknowledgement

.Contact Us      .Comments/Suggestions       Email2aFriend    |

 

How to rename a multiple UNIX file system?

 

More Resources by Google:

 

By: Jeff Turner

#

#!/bin/ksh

# Korn shell script

#

# Script to rename files as per the DOS routine A* B*

# Author: Jeff Turner, Context-Switch Limited

# Creation Date: April 3rd, 2002

# Version: 1.0

 

# declare variables that will be used in the script

integer charcount=0 lencount=0 diff=0

bon="$(tput smso)"

boff="$(tput rmso)"

 

# clear screen and display message to user

while true

do

clear

echo "File ReNamer Program

 

This program allows you to rename files by changing the first

few characters of the filename.

 

For example:

 

            Axxxxx can become Bxxxxx

            AAxxxx can become BBxxxx

            and so on.

 

You will be asked for the following:

 

            1) characters to be replaced

            2) characters to replace with

 

NOTE:

This program assumes that the change will be applied to files

in the current directory.

 

${bon}To terminate this program, use Control-C ${boff}

 

1) Please enter the filename characters to be replaced: \c"

 

# read user input

read STARTCHARS ignorerest

 

# now test input

if [ -z "$STARTCHARS" ]

then      # user entered no characters

 

            echo "\aERROR!  You must enter something!"

            sleep 2

            continue          # go back to start of loop

fi

 

echo "\n2) Now, enter the replacement characters: \c"

# read user input

read REPLACECHARS ignorerest

 

# now test input

if [ -z "$REPLACECHARS" ]

then      # user entered no characters

 

            echo "\aERROR!  You must enter something!"

            sleep 2

            continue          # go back to start of loop

fi

 

break   # if we get this far, it is ok to move on to next stage

 

done     # end loop

 

echo "\n"

 

# now to find files that match the criteria and effect the change

FILELIST=${STARTCHARS}*

 

for VAR in $FILELIST

do

 

            charcount=${#STARTCHARS}

            lencount=${#VAR}

            ((diff = lencount - charcount ))

            if (( diff > 0 ))

            then

                        tempname=$VAR

                        eval typeset -R$diff tempname

                        NEWNAME="${REPLACECHARS}${tempname}"

 

                        # now rename the file(s)

                        mv $VAR  $NEWNAME && echo "Renamed  $VAR  to  $NEWNAME"

            else

                        continue          # back to start of loop again

            fi

done

 

Good Luck!

 

Google
 
Web web site