DIR= SRCSUFFIX= DESTSUFFIX= if [ $# -ne 3 ]; then echo ">

把当前目录下指定后缀名修改为其他后缀名 -电脑资料

电脑资料 时间:2019-01-01 我要投稿
【www.unjs.com - 电脑资料】

   

    [plain]

    #!/bin/bash

    #把指定目录下的所有指定后缀名的文件替换为指定后缀名的文件

    SELF=$0

    DIR=$1

    SRCSUFFIX=$2

    DESTSUFFIX=$3

    if [ $# -ne 3 ]; then

    echo "$SELF path,srcSuffix, destSuffix"

    exit 0

    fi

    if [ -d $DIR ]; then

    echo "$DIR is validate directory."

    else

    echo "$DIR is invalidate directory."

    exit 0

    fi

    find $DIR -name *.$SRCSUFFIX | while read i

    do

    SRCNAME=$i

    echo "srcName is $SRCNAME";

    DESTNAME=${SRCNAME%.*}.$DESTSUFFIX

    echo "destName is $DESTNAME";

    mv $SRCNAME $DESTNAME

    done

    工作中经常要把当前目录下指定后缀名(如×,

把当前目录下指定后缀名修改为其他后缀名

电脑资料

把当前目录下指定后缀名修改为其他后缀名》(https://www.unjs.com)。cc)修改为指定后缀名(×。cpp)。写了一个脚本来做这个事情,在linux下测试通过。

最新文章