Linux 批量改名

Posted by Sunday on 2019-11-22

批量修改SSL证书前后缀,并拷贝至新建目录

修改前 to 修改后
1_api.sundayle.com_bundle.crt to api.sundayle.com.pem
2_api.sundayle.com.key to api.sundayle.com.key

1
2
3
4
5
6
7
8
9
10
11
12
13
14
find ./*/Nginx/*

./api.sundayle.com/Nginx/1_api.sundayle.com_bundle.crt
./api.sundayle.com/Nginx/2_api.sundayle.com.key
./mall.sundayle.com/Nginx/1_mall.sundayle.com_bundle.crt
./mall.sundayle.com/Nginx/2_mall.sundayle.com.key
./manage.sundayle.com/Nginx/1_manage.sundayle.com_bundle.crt
./manage.sundayle.com/Nginx/2_manage.sundayle.com.key
./oauth.sundayle.com/Nginx/1_oauth.sundayle.com_bundle.crt
./oauth.sundayle.com/Nginx/2_oauth.sundayle.com.key
./pay.sundayle.com/Nginx/1_pay.sundayle.com_bundle.crt
./pay.sundayle.com/Nginx/2_pay.sundayle.com.key
./static.sundayle.com/Nginx/1_static.sundayle.com_bundle.crt
./static.sundayle.com/Nginx/2_static.sundayle.com.key
1
rename "s/AA/aa/" * #把文件名中的AA替换成aa
1
2
3
4
5
6
find ./*/Nginx/* -name "1_*_bundle.crt" | xargs rename "s/_bundle.crt/.pem/"
find ./*/Nginx/* -name "1_*" | xargs rename "s/1_//"
find ./*/Nginx/* -name "2_*" | xargs rename "s/2_//"

mkdir 22/
find ./*/Nginx/* -name "*.pem" -o -name "*.key" |xargs -i cp {} ./22
1
2
3
4
5
6
7
8
9
10
11
12
13
14
ls -l 22/
total 48
-rw-r--r-- 1 root root 1704 Nov 22 11:59 api.sundayle.com.key
-rw-r--r-- 1 root root 3701 Nov 22 11:59 api.sundayle.com.pem
-rw-r--r-- 1 root root 1704 Nov 22 11:59 mall.sundayle.com.key
-rw-r--r-- 1 root root 3709 Nov 22 11:59 mall.sundayle.com.pem
-rw-r--r-- 1 root root 1700 Nov 22 11:59 manage.sundayle.com.key
-rw-r--r-- 1 root root 3713 Nov 22 11:59 manage.sundayle.com.pem
-rw-r--r-- 1 root root 1704 Nov 22 11:59 oauth.sundayle.com.key
-rw-r--r-- 1 root root 3709 Nov 22 11:59 oauth.sundayle.com.pem
-rw-r--r-- 1 root root 1704 Nov 22 11:59 pay.sundayle.com.key
-rw-r--r-- 1 root root 3709 Nov 22 11:59 pay.sundayle.com.pem
-rw-r--r-- 1 root root 1700 Nov 22 11:59 static.sundayle.com.key
-rw-r--r-- 1 root root 3713 Nov 22 11:59 static.sundayle.com.pem

https://blog.csdn.net/u014696921/article/details/56673532