shell统计指定目录、指定模式的文件行数
来源:互联网 发布:网络战是未来趋势 编辑:程序博客网 时间:2024/05/16 17:26
1、统计指定目录下文件个数(默认当前目录)
#!/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 doneelse funCount "."fiecho "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=0function funCount(){ for file in ` ls $1 ` doif [ $# -gt 1 ];thenif [ -f $1"/"$file ] thenif [[ $1"/"$file = $1"/"$2 ]]then declare -i fileLines fileLines=`sed -n '$=' $1"/"$file` let llines=$llines+$fileLines count=`expr $count + 1`fifi elseif [ -f $1"/"$file ] thendeclare -i fileLines fileLines=`sed -n '$=' $1"/"$file` let llines=$llines+$fileLinescount=`expr $count + 1`fi fi done}dirs=`sed -n '/^[^#]/p' dirs`if [ $# -eq 1 ];thenfor dir in $dirs do funCount $dir $1 doneelif [ $# -eq 0 ] ; then for dir in $dirs do funCount $dir doneelse echo "args error!!!"fiecho "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.
0 0
- shell统计指定目录、指定模式的文件行数
- 统计指定目录下,指定文件后缀的文件代码行数,并排序
- 统计指定目录下,指定后缀文件的个数及内容行数
- Python 实例一 统计指定文件的行数或读取指定文件指定行数的内容
- 统计指定类型文件行数
- 递归算法-统计指定目录下java文件内容的行数
- python统计指定目录内文件的代码行数
- Shell脚本统计指定目录下子目录中的文件个数
- 统计文件夹内指定类型文件的代码行数(二)
- 一条shell统计当前目录下的文件行数
- 统计文件行数的shell
- [shell] -- linux下日志文件的指定起始行和指定行数读取
- shell 删除指定目录下过时的文件或目录
- linux Shell: 定时清理指定目录下大于指定大小、指定文件名的文件?
- 启动shell的调试模式 set -x ,find 当前目录下的指定类型文件
- Shell命令--怎么统计文本中第一列数据满足指定条件的行数
- 统计指定目录下的文件的小程序
- 如何统计指定目录下的文件个数
- 查看电脑安装的.net版本
- update的优化
- oracle同义词
- WebAPP与原生APP的交互设计区别
- 第33讲-项目二-求阶乘
- shell统计指定目录、指定模式的文件行数
- ecshop后台系统设置-商店设置详解
- cocs2dx中c++与c#互调
- Linux 开机执行一条shell命令
- 烫烫烫,锟斤拷
- kpush源码解析---服务端(alloc server)
- django-orm中F对象的使用
- 安卓的进程和线程
- linux内核--wait_event_interruptible_timeout()函数分析