shell脚本遍历当前目录下以数字命名的目录,并打印

#!/bin/bash

single=''  #定义以个位数为目录的集合
double=''  #定位十位数为目录的集合
#按照需要可以根据实际情况再定义以百位数为目录的集合

for dir in `ls -d [0-9]*`    #开始遍历
do
   if [ `ls -d [0-9]* | wc -l` -ge 10 ];then  #判断当前的目录总数是否大于等于10
      if [ `echo $dir | wc -c` = 2 ];then  #判断是否为个位数的目录
            single="${single} $dir"  #加入到集合中
      else
            double="${double} $dir"  #加入到集合中
      fi
   fi

done

for dirname in ${single}
do
   echo "#TODO $dirname"
done
for dirname in ${double}
do
   echo "#TODO $dirname"
done

#echo ${single}
#echo ${double}

遍历目录,并删除掉一些目录的方法
#!/bin/bash

root_path="/opt/path"
for dir in `ls ./`
do
        cd "${root_path}/${dir}"
        echo "${dir}==dir"
        for subdir in `ls ./`
        do
                cd "${root_path}/${dir}/${subdir}"
                echo "${subdir}==sub dir."
                for ssdir in `ls -t | awk 'NR>40{print $1}'`
                do
                        echo "ssdir==${ssdir}"
                        echo "abs path=${root_path}/${dir}/${subdir}/${ssdir}/"
                        rm -rf ${root_path}/${dir}/${subdir}/${ssdir}
                        ls ${root_path}/${dir}/${subdir}/${ssdir}
                done
        done

done
 
all_ports=`echo ${all_ports} | sed -e "s/,${port},/,/g"`
change(){
    rep=$1
    posts=`get_port`
    port=`echo ${posts} | awk -F , '{print $2}'`
    ja="ja_co_co=\" -javaagent:${JACOCOAGENT}=includes=\*,output=tcpserver,port=${port},address=\*,append=true\""
    if [ -f "${ss}"  ];then
       echo "${rep} === ${posts}"
       echo "${ss}"
       sed -i "/^[[:space:]]*nohup java/i\\${ja}" ${ss}
       sed -i "s/^[[:space:]]*nohup java/& \$\{ja_co_co\}/g" ${ss}
       #sed -i "/^${rep}/a${rep}=\"\ \$\{${rep}\}\ ${arg}\ \"" ${ss}
    fi

}


                
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值