环境说明:
[root@test2 test]# ls -l
total 16
drwxr-xr-x 2 root root 4096 Nov 16 11:59 4030
drwxr-xr-x 2 root root 4096 Nov 16 11:59 4031
drwxr-xr-x 2 root root 4096 Nov 16 11:59 4032
-rwxr-xr-x 1 root root 369 Nov 15 16:16 rename_pic.sh
-rwxr-xr-x 1 root root 518 Nov 16 11:59 test.sh
[root@test2 test]# cd 4030
[root@test2 4030]# ls
[root@test2 4030]# ls
kingtaifook_desc.html kingtaifook_dimg6.jpg kingtaifook_kaixin.jpg
kingtaifook_dimg1.jpg kingtaifook_dimg7.jpg kingtaifook_kb.html
kingtaifook_dimg2.jpg kingtaifook_dimg8.jpg kingtaifook_main.jpg
kingtaifook_dimg3.jpg kingtaifook_dimg9.jpg kingtaifook_side.jpg
kingtaifook_dimg4.jpg kingtaifook_eva.html kingtaifook_small.jpg
kingtaifook_dimg5.jpg kingtaifook_hao123.jpg kingtaifook_wb.html
需要实现的是把kingtaifook_dimg1.jpg 修改成4030_dimg1.jpg,并把原来的图片保留.
[root@test2 test]# cat rename_pic.sh
#!/bin/bash
#set -x
for dir in `ls | grep -v 'sh$'`
do
cd $dir
EXC=`ls *.jpg |head -n 1 | awk -F\_ '{print $1}'`
for file in `ls *.jpg`
do
find ./ -name "$EXC_*.jpg" -exec cp "{}" {}.1 \;
find ./ -name "$EXC_*.jpg.1" -exec rename $EXC $dir {} \;
find ./ -name "*.jpg.1" -exec rename jpg.1 jpg {} \;
done
cd ..
done
exit 0
测试了下用[root@test2 4030]# rename 's/kingtaifook/4030/g' *.jpg 这个方法实现不了.
不知道有没有更好的方法.
阅读(1964) | 评论(0) | 转发(0) |