Shell脚本,用法如下

1
./batch_rename.sh FOLDER -old OLD_STR -new NEW_STR

batch_rename.sh

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#!/bin/bash

folder=$1

if [ ! -d $folder ]; then
echo "缺少目录"
exit
fi

shift

while echo $1 | grep ^- > /dev/null; do
eval $( echo $1 | sed 's/-//g' | tr -d '\012')=$2
shift
shift
done

files=`find ${folder} | grep ${old}`
for file in $files; do
mv "$file" "${file//${old}/${new}}"
done