shell统计指定目录、指定模式的文件行数
2015-05-14 17:54
260 查看
1、统计指定目录下文件个数(默认当前目录)
实例:
[root@localhost sourcetemp]# sh filecount
There are 75 files .
[root@localhost sourcetemp]# sh filecount test
There are 75 files .
2、根据配置文件读取指定的目录,再根据输入参数(模糊)匹配对应目录下的文件:
实例:
[root@adiislogdata164 action]# sh c1.sh
There are 410 files.
There are 398091119 lines.
[root@adiislogdata164 action]# sh c1.sh front_action.log.2015-05-13-*
There are 240 files.
There are 234195303 lines.
#!/bin/bash #统计指定目录下文件个数(默认当前目录) count=0 function funCount() { for file in ` ls $1 ` do if [ -f $1"/"$file ] then count=`expr $count + 1` fi done } if [ $# -gt 0 ];then for m_dir in $@ do funCount $m_dir done else funCount "." fi echo "There are $count files."
实例:
[root@localhost sourcetemp]# sh filecount
There are 75 files .
[root@localhost sourcetemp]# sh filecount test
There are 75 files .
2、根据配置文件读取指定的目录,再根据输入参数(模糊)匹配对应目录下的文件:
#!/bin/bash #统计指定目录下符合规则的文件个数 front_action.log.2015-05-14-* count=0 llines=0 function funCount() { for file in ` ls $1 ` do if [ $# -gt 1 ];then if [ -f $1"/"$file ] then if [[ $1"/"$file = $1"/"$2 ]] then declare -i fileLines fileLines=`sed -n '$=' $1"/"$file` let llines=$llines+$fileLines count=`expr $count + 1` fi fi else if [ -f $1"/"$file ] then declare -i fileLines fileLines=`sed -n '$=' $1"/"$file` let llines=$llines+$fileLines count=`expr $count + 1` fi fi done } dirs=`sed -n '/^[^#]/p' dirs` if [ $# -eq 1 ];then for dir in $dirs do funCount $dir $1 done elif [ $# -eq 0 ] ; then for dir in $dirs do funCount $dir done else echo "args error!!!" fi echo "There are $count files." echo "There are $llines lines."
实例:
[root@adiislogdata164 action]# sh c1.sh
There are 410 files.
There are 398091119 lines.
[root@adiislogdata164 action]# sh c1.sh front_action.log.2015-05-13-*
There are 240 files.
There are 234195303 lines.
相关文章推荐
- shell统计指定目录下所有文件类型及数量
- 递归算法-统计指定目录下java文件内容的行数
- shell统计指定目录下所有文件类型及数量
- 统计指定目录下,指定后缀文件的个数及内容行数
- linux下shell统计文件目录下所有代码行数
- 统计指定目录下,指定文件后缀的文件代码行数,并排序
- java统计某文件或目录下指定路径的文件数量及行数
- Shell脚本统计指定目录下子目录中的文件个数
- 一个用shell写的统计目录下统计文件行数的代码
- python统计指定目录内文件的代码行数
- 启动shell的调试模式 set -x ,find 当前目录下的指定类型文件
- shell查找指定目录下的关键字文件
- 使用shell脚本统计各个模块每个文件代码行数与总行数
- bash shell 遍历指定目录下文件 iconv 编码转换
- 统计文件夹内指定类型文件的代码行数(二)
- shell统计某目录下文件和文件夹的数量
- 输出该目录下指定类型文件(.cs, .java)的个数、文件的总行数、空行数、注释行数、代码行数
- shell 脚本 打印指定目录下包含某些字符串的文件
- shell脚本删除目录下的指定文件
- shell如何统计文本文件行数