shell批量重命名
第一种方法:
num=`ls *.jpg | wc -l`;
echo -e "照片总数:$num \n"count=1
for file in $(ls -v *.jpg); donew_file=${count}.jpgecho "$file --> $new_file"mv "$file" "${new_file}"((count+=2))
done
运行结果:
第二种方法:
#仅适合前缀固定,后缀数字连续的情况。需要设定前缀
prefix=IMG_20241114_094237_BURSTcount=`ls *.jpg | wc -l`;
echo -e "照片总数:$count \n"suff=1
for ((i=1;i<=count;i++))
dofile="${prefix}${i}.jpg"new_file=${suff}.jpgecho "$file --> $new_file"mv "$file" "${new_file}"((suff+=2))
done
运行结果: