#!/bin/bash SAVEIFS=$IFS export IFS=$'\n'; CDIR=$(pwd) read -p "any name to replace: " startold read -p "name to use instead: " startnew echo "Renaming from ${startold} to ${startnew} ";\ if (pwd | grep -c '\/home\/mobaxterm'); then echo "Correct Directory" echo " " else echo "Wrong Directory" echo " " # exit 0 fi for i in `find $CDIR -maxdepth 0 -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}/g"` newfile=`echo "${file}" | sed ${sedstr}` echo "moving ${file} to ${newfile}" mv -n ${file} ${newfile} done cd "$CDIR" done IFS=$SAVEIFS