Batch modify file suffix-shell script

ps: No recursive query in the current directory, where HZ1 is the suffix before modification, and HZ2 is the modified one

#!/bin/bash
HZ1=$1 
HZ2=$2
if [[ "$1" == "" ]] ;then
HZ1=repo
HZ2=bak
echo "默认源文件后缀为:repo 修改后后缀为:bak"
fi
PWD=`pwd`
echo "$PWD"
if [ "$PWD" == "" ];then
echo "获取文件工作路径,请重试"
exit -1
fi
Len=${#HZ1} 
echo "长度:$Len"
for i in `find ./*.$HZ1 -type f`
do
echo "修改前:${i:2}"
echo "修改后:${i:2:-4}$HZ2"
mv $PWD/${i:2} $PWD/${i:2:-4}$HZ2
done

Test:
Remove all files with suffix bak in the current directory
Insert picture description here

Guess you like

Origin blog.csdn.net/qq_38774492/article/details/108097006