Shell脚本统计指定目录下子目录中的文件个数
2016-06-06 19:53
585 查看
#!/bin/bash
function usage(){
echo ""
echo "introduction: count of files subdir of source dir to save file.txt with [[subdir] [number of files]"
echo "subdir_files_count: usage: bash subdir_files_count -s [source dir] -o [output file ]"
exit 1
}
while getopts "s:o:" arg #选项后面的冒号表示该选项需要参数
do
case $arg in
s)
source="$OPTARG" #参数存在$OPTARG中
;;
o)
output="$OPTARG"
;;
?) #当有不认识的选项的时候arg为?
echo "unkonw argument"
usage
;;
esac
done
if [ -z $source ]
then
usage
fi
if test ! -d $source
then
echo "$source not exists!"
exit 1
fi
dir_list=`ls $source | sort`
for sub_dir in $dir_list
do
if test -d "$source/$sub_dir"
then
fcout=`ls $source/$sub_dir | wc -l`
echo "$sub_dir $fcout" >> $output
fi
done
function usage(){
echo ""
echo "introduction: count of files subdir of source dir to save file.txt with [[subdir] [number of files]"
echo "subdir_files_count: usage: bash subdir_files_count -s [source dir] -o [output file ]"
exit 1
}
while getopts "s:o:" arg #选项后面的冒号表示该选项需要参数
do
case $arg in
s)
source="$OPTARG" #参数存在$OPTARG中
;;
o)
output="$OPTARG"
;;
?) #当有不认识的选项的时候arg为?
echo "unkonw argument"
usage
;;
esac
done
if [ -z $source ]
then
usage
fi
if test ! -d $source
then
echo "$source not exists!"
exit 1
fi
dir_list=`ls $source | sort`
for sub_dir in $dir_list
do
if test -d "$source/$sub_dir"
then
fcout=`ls $source/$sub_dir | wc -l`
echo "$sub_dir $fcout" >> $output
fi
done
相关文章推荐
- 变量+shell变量(1)
- Shell整理(持续更新中)
- linux命令存放 bash: xxx command not found
- 解决Xshell显示中文乱码的问题
- 配置Xshell的 鼠标选中即复制,右键即粘贴的功能!
- git shell 命令集合
- sed的模式空间和保持空间
- android linux shell 日期设置
- 让shell脚本中的echo输出带颜色
- shell脚本学习笔记 (文本处理器AWK)
- Linux shell : 史上最简单的系统备份脚本
- shell系列------查看storage下有没有某个文件目录
- windows的cmd下的find命令比bash(win10下的Ubuntu的bash)下的grep比较
- Linux shell快速查找PHP木马
- shell date 常用命令
- 认识bash 这个Shell
- -bash: ulimit: open files: cannot modify limit: Operation not permitted
- shell 自定义函数
- 25个简单shell例子
- shell中trap捕获信号