grep 自动匹配当前目录下的.sh结尾的更改为.txt

#!/bin/bash
for i in `ls|egrep sh$`  //用到egrep 正则匹配结尾为sh的
do 
        mv $i `echo $i|cut -d. -f1`.txt //提取除了.sh前面的部分 字符串拼接.txt
done

  

原文地址:https://www.cnblogs.com/gaiting/p/12164789.html