preface

Sectigo AddTrust External CA Root Expiring May 30, 2020 Sectigo AddTrust External CA Root Expiring May 30, 2020 Say too much is tears.

Update history

31 May 2020 – First draft

Read the original – wsgzao. Making. IO/post/bash – r…


Their thinking

  1. You need to traverse the directory
  2. You need to rename the files ending in *. Key and *. CRT to server.key and SSL.chain-crt

Linux commands recursively modify file names (including folders)

I searched the key words on the Internet and found that the script was quite clear, but it still needs to be modified

#! /bin/bash
function changeName() {#new=`echo $1|sed 's/^/abc/g'`
    new=`echo The $1|sed -r 's/abc(.*$)/\1/g'`
    echo changeName old: The $1 new: $new
    if [ The $1! =$new ];then
        mv The $1 $new
    fi
}

function travFolder() {#echo "travFolder start"
    flist=`ls The $1`
    cd The $1
    for f in $flist
    do
        #echo traverse do $f
        local old=$f
        if test -d $f
        then
            #echo "traverse dir:${f}"
            travFolder $f
            #echo "traverse rename dir:${f}"
            changeName $old #rename folder
        else
            #echo "traverse file:$f"
            changeName $f
        fi
    done
    cd ../
}

param=The $1
if [ -z "The $1" ]
    then
    param=". /"
    echo "empty string: $param"
else
    param=The $1
fi
travFolder $param
Copy the code

The modified code

If you’re considering using Rename to simplify code, check out this Stack Overflow article

How to Batch Rename Files in a macOS Terminal?

#! /bin/bash
function travFolder() {#echo "travFolder start"
    flist=`ls The $1`
    cd The $1
    for f in *.key; do mv "$f" "server.key"; done
    for f in *.crt; do mv "$f" "ssl.chain.crt"; done
    for f in $flist
    do
        #echo traverse do $f
        if test -d $f
        then
            #echo "traverse dir:${f}"
            travFolder $f
        fi
    done
    cd ../
}

param=The $1
if [ -z "The $1" ]
    then
    param=". /"
    echo "empty string: $param"
else
    param=The $1
fi
travFolder $param

Copy the code

Refer to the article

How to recursively modify file names (including folders)