batch_modify.sh
#!/bin/bash
#Description:ShellName.sh txt log(将txt后缀的文件修改为log)
for i in $(ls *.$1)
do
mv $i ${i%.*}.$2
#${string%substring}指从$string的结尾位置截掉最短匹配的$substring
done
验证
[root@elasticsearch ~]# ls *.txt
1.txt 2.txt 3.txt
[root@elasticsearch ~]# sh batch_modify.sh txt log
[root@elasticsearch ~]# ls *.log
1.log 2.log 3.log
[root@elasticsearch ~]#