满意答案
单纯的依靠mv命令做不到,需要脚本来实现
编写脚本 rename 如下
#----------------------------------------------
#!/bin/sh
ls -l $1 | grep ^[^d] | awk '{print $9}'| while read line; do
do=`echo $line | grep $2`
if [ ! "$do" = "" ]; then
newname=`echo $line | sed 's/'$2'/'$3'/g'`
echo "rename $line to $newname ..."
mv $1/$line $1/$newname
fi
done
#------------------------------------------------
将以上保存为 rename文件,
然后运行
chmod +x rename
使rename可运行
然后按照如下格式执行rename
假设rename在当前路径
$./rename [fullpathtofiles] .sql.cluster1 .sql
[fullpathtofiles] 指向你的BAOAN102671.sql.cluster1 这些文件的全路径即可
参考以下我的演示 ,将具体路径替换到你的即可,实际测试通过
--------------------------------
root@bogon~/testmv# ls
12343234234.sql.cluster1 323423423423.sql.cluster1 sdfdssddd.sql.cluster1
root@bogon~/testmv# cd ..
root@bogon~# ./rename ./testmv/ .sql.cluster1 .sql
rename 12343234234.sql.cluster1 to 12343234234.sql ...
rename 323423423423.sql.cluster1 to 323423423423.sql ...
rename sdfdssddd.sql.cluster1 to sdfdssddd.sql ...
root@bogon~# cd testmv
root@bogon~/testmv# ls
12343234234.sql 323423423423.sql sdfdssddd.sql
-----------------------------------------------------
00分享举报