您的位置:首页 > 运维架构 > Linux

linux 脚本功能:查找某个文件夹,将符合条件文件夹的指定文件名拷贝成其他的文件名

2011-12-07 18:19 656 查看
#脚本功能:查找某个文件夹,将符合条件文件夹的指定文件名拷贝成其他的文件名

#shell点:遍历文件夹,判断指定文件路径,查找文件,文件名替换

#!/bin/sh

func(){

curdir=$1

local path=$curdir

for file in `ls $curdir`

do

if [ -d "$path/$file" ];then

func "$path/$file"

elif [ -f "$path/$file" ];then

#if [ -n "`echo $path|grep 142`" ]#只检查一个字符

if [ -n "`echo $path|grep -E "(141|142)$"`" ]#可以检查多个字符

then

if [ -n "`echo $file|grep _100_100`" ]

then

old=$file

new=${old/_100_100/_180_140}

new2=${old/_100_100/_240_240}

cp "$path/$old" "$path/$new"

cp "$path/$old" "$path/$new2"

echo "$new"

echo "$new2"

echo "$path/$new"

echo "$path/$new2"

fi

echo "$path/$file"

fi

fi

done

}

func "/r/img/2011"
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  linux shell 休闲 cp grep