linux: batch modify the name of the folder and the file under the folder

Suppose I have a folder with some files under it like this:
Gideon/gideon_lisha/Gideon_samuel/Gideon_nathan.xml
Gideon/lisha_gideon/Gideon_noah.xml

 

I am currently in the Gideon folder in the root directory. I want to write a shell code. This folder and all Gideons under the folder are replaced by Liang. The result I want is as follows:

Liang/Liang_lisha/Liang_samuel/Liang_nathan.xml
Liang/lisha_Liang/Liang_noah.xml

 

my code:

replace_file_names.sh

#!/bin/bash

path=$1
filename=$2
newfilename=$3

echo "We are finding '$filename' under the folder '$path'"

count=1
for i in `find $path -iname "*$filename*" | tac`
do
    newpath=`echo $i | sed "s@\(.*\)$filename@\1$newfilename@i"`
    sudo mv "$i" "$newpath"
    echo "${count}: Renaming $i to $newpath"
    let count++
done

 

Thank susbarbatus

 

Original/From: linux: Batch modify the names of folders and files under folders

 

 

 

 

 

 

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326987413&siteId=291194637