- #将后缀名为.rmvb 改为 .avi, 将会递归将本目录下面所有文件进行更改
- #! /bin/bash
- SUFFIX=".avi"
- if [ -z $1 ] #判断是否带参数,没带参数以当前目录为默认值
- then
- echo "arg is null, reset it as ./"
- DIREC=$PWD
- else
- echo "set $1 as dir"
- DIREC=$1
- fi
- function SUFFIX_CHANGE()
- {
- for file in $1/*
- do
- if [ -d $file ] #如果是目录文件进行递归调用
- then
- echo "$file dir file"
- SUFFIX_CHANGE $file
- fi
- filename=`expr match "$file" '\(.*rmvb\)'` #对文件进行匹配
- if [ -z $filename ]
- then
- echo "$file is not match!!"
- continue
- else
- filename=${file%.*rmvb} #去掉旧的后缀名
- filename+=$SUFFIX #添加新的后缀名
- echo "rename $file to $filename"
- `mv -f $file "$filename"` #重新名命
- fi
- done
- return 0
- }
- SUFFIX_CHANGE $DIREC #函数调用
- echo "exit shell"
- exit 0