Hello world

shell:遍历目录和子目录的所有文件

#!/bin/bash
function getdir(){
    for element in `ls $1`
    do  
        dir_or_file=$1"/"$element
        if [ -d $dir_or_file ]
        then 
            getdir $dir_or_file
        else
            echo $dir_or_file
        fi  
    done
}
root_dir="/home/test"
getdir $root_dir

#以下命令均不包含".",".."目录,以及"."开头的隐藏文件,如需包含,ll 需要加上 -a参数
#当前目录下文件个数,不包含子目录
ll |grep "^-"|wc -l
#当前目录下目录个数,不包含子目录
ll |grep "^d"|wc -l
#当前目录下文件个数,包含子目录
ll -R|grep "^-"|wc -l
#当前目录下目录个数,包含子目录
ll -R|grep "^d"|wc -l

 

借鉴自他人,仅为方便以后查看

posted @ 2016-12-23 14:25  hershell  阅读(50794)  评论(0编辑  收藏  举报