zoukankan      html  css  js  c++  java
  • shell:递归遍历文件夹及其子文件夹

     1 #!/bin/bash
     2 #遍历文件夹及其子文件夹内所有文件,并查看各个文件大小
     3 dir="/root/test" #要遍历的目录
     4 
     5 #子函数getdir
     6 function getdir()
     7 {   
     8     for element in `ls $1`
     9     do  
    10         file=$1"/"$element
    11         if [ -d $file ]
    12         then 
    13             getdir $file
    14         else
    15             echo $file 1>> /root/dir.out #将结果保存到/root/dir.out
    16         fi  
    17     done
    18 }
    19 
    20 getdir $dir #引用子函数
    21 for line in `cat /root/dir.out`  #读取文件dir.out的每行
    22 do
    23     filesize=`ls -l $line | awk '{ print $5 }'`  #读取文件大小
    24     echo $filesize
    25 done
  • 相关阅读:
    RedissonConfProperty
    IdGenerator(雪花)
    Btrace和arthas地址
    SqlFilter
    AuthorityFilter
    111
    分布式数据库-杂记
    站点集群
    分布式精华文章
    高并发
  • 原文地址:https://www.cnblogs.com/seaBiscuit0922/p/7510449.html
Copyright © 2011-2022 走看看