美文网首页
shell批量替换

shell批量替换

作者: 不要和哥闹 | 来源:发表于2021-04-09 16:31 被阅读0次
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批量替换

      本文链接:https://www.haomeiwen.com/subject/elopkltx.html