将所有txt重命名为L_1.txt
#!/bin/bash i=0 for name in .txt do echo "$name" let i=i+1 echo "$i" mv "$name" l_$i.txt done
将所有1_1.txt重命名为100.txt
#!/bin/bash i=0 for name in .txt do echo "$name" if [ "$name" == "l_1.txt" ]; then mv "$name" 100.txt fi done
遍历所有目录取目录最后一个字符重命名目录
#!/bin/bash for name in do echo "$name" mv "$name" ${name:0-1} done
遍历所有子目录中文件,对子目录中文件进行重命名
for file in do for sub in ./$file/* do echo $sub if [ "$sub" == "./${file}/111.txt" ]; then mv "$sub" ./$file/1.txt fi if [ "$sub" == "./${file}/222.txt" ]; then mv "$sub" ./$file/2.txt fi if [ "$sub" == "./${file}/333.txt" ]; then mv "$sub" ./$file/3.txt fi done #echo $file done