1. #将后缀名为.rmvb 改为 .avi, 将会递归将本目录下面所有文件进行更改
  2.  
  3. #! /bin/bash 
  4.  
  5. SUFFIX=".avi" 
  6.  
  7. if [ -z $1 ] #判断是否带参数,没带参数以当前目录为默认值
  8. then 
  9.         echo "arg is null, reset it as ./" 
  10.         DIREC=$PWD   
  11. else     
  12.         echo "set $1 as dir" 
  13.     DIREC=$1 
  14. fi 
  15.  
  16.  
  17.  function SUFFIX_CHANGE() 
  18.     for file in $1/* 
  19.     do 
  20.  
  21.         if [ -d $file ] #如果是目录文件进行递归调用
  22.         then 
  23.             echo "$file dir file" 
  24.             SUFFIX_CHANGE $file 
  25.         fi 
  26.  
  27.         filename=`expr match "$file" '\(.*rmvb\)'` #对文件进行匹配
  28.  
  29.         if [ -z $filename ] 
  30.         then 
  31.             echo "$file is not match!!" 
  32.             continue 
  33.         else             
  34.             filename=${file%.*rmvb} #去掉旧的后缀名
  35.             filename+=$SUFFIX #添加新的后缀名
  36.             echo "rename $file to $filename" 
  37.             `mv -f $file "$filename"` #重新名命
  38.         fi 
  39.     done 
  40.     return 0 
  41.  
  42. SUFFIX_CHANGE $DIREC #函数调用
  43.  
  44. echo "exit shell" 
  45.  
  46. exit 0