首页 > 代码库 > 递归遍历目录拷贝cdh下的lib到一个目录

递归遍历目录拷贝cdh下的lib到一个目录

destpath=‘/home/hadoop/soft/hadoop-2.0.0-cdh4.5.0/cdhlib/‘
jarpath=‘/home/hadoop/soft/hadoop-2.0.0-cdh4.5.0/share/hadoop/‘
search=‘jar‘

iterdir(){
    cd $1
    for p in `ls`; do
        echo "$p" |grep -q "$search"
        if [ $? -eq 0 ]
        then
                echo "file $p"
                cp -rf $p "$destpath$p"
        else
                if [ -d "$p" ] && [ "$p" != "mapreduce1" ]; then
                        cd $p
                        basepath=$(cd `dirname $0`; pwd -P)
                        iterdir $basepath
                        cd ..

                fi
        fi
    done
}

iterdir $jarpath