shell批量替换

CURRENT_DIR=`pwd`

for dir in *
do
    if [ -d $dir ];then
        for file in $dir/*
        do
            NEW_FILE=${file/XXXXXXX/}
            if [ "$NEW_FILE" != "$file" ] ;then
                mv "${CURRENT_DIR}/$file" "${CURRENT_DIR}/${NEW_FILE}"
                if [ $? -eq 0 ] ;then
                    echo "${CURRENT_DIR}/${NEW_FILE}"
                    echo "替换成功"
                fi
            fi
            #echo $CURRENT_DIR ----- $dir --- $file
            
        done
    fi
    
done

你可能感兴趣的:(shell批量替换)