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 }




原文地址:https://www.cnblogs.com/wozijisun/p/6774599.html