Files
shellfiles/bin/wsl/rename_start.sh
2026-01-19 21:36:25 -05:00

36 lines
750 B
Bash
Executable File

#!/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