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

shell 递归拷贝目录下的制定文件

2014-02-14 13:41 225 查看
export arrayindex
export array
function  scandir() {
local cur_dir parent_dir workdir
workdir=$1
cd ${workdir}
if [ ${workdir} = "/" ]
then
cur_dir=""
else
cur_dir=$(pwd)
fi
for dirlist in $(ls ${cur_dir})
do
if test -d ${dirlist};then
cd ${dirlist}
scandir ${cur_dir}/${dirlist}
cd ..
else
# echo ${cur_dir}/${dirlist}
#数组赋值
array[$arrayindex]=${cur_dir}/${dirlist}
#注意值递增的方式
((arrayindex++))
fi
done
}
function GetALLDirInfo()
{
local dir
dir=$1
arrayindex=0
if test -d $dir
then
scandir $dir
elif test -f $dir
then
echo "you input a file not a directory"
exit 1
else
echo "the dir you input $dir is not exit"
fi
}
read -p "please input the dir path:" DIR
echo "path is:$DIR"
GetALLDirInfo $DIR
for content in ${array[@]}
do
#注意这里一定是ls命令,还有后面的通过管道来调用CP命令
ls  $content|grep 'txt'|awk '{print $0}' |xargs -I {} cp {}  /home/song/temp1
done
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
相关文章推荐