#!/bin/bash SAVEIFS=$IFS export IFS=$'\n'; CDIR=$(pwd) read -p "starting name to replace: " startold read -p "starting name to use instead: " startnew echo "Renaming from ${startold} to ${startnew} ";\ if (pwd | grep -c '\/home\/mobaxterm'); then echo "Correct Directory" echo " " else echo "Recursive!! Are you sure? CTRL-C to terminate." # sleep 2 echo " " # exit 0 fi for i in `find $CDIR -type d -print`; do DIR=$i cd "$DIR" echo "Inside $DIR :" for file in `find . -maxdepth 1 -type f -iname "${startold}*"`; do sedstr=`echo "s/${startold}/${startnew}/"` newfile=`echo "${file}" | sed ${sedstr}` echo "moving ${file} to ${newfile}" mv -n ${file} ${newfile} done cd "$CDIR" done IFS=$SAVEIFS