此shell脚本完成:根据用户输入的主目录,显示其下各个子目录中的.txt和.sh文件的数目
#!/bin/sh
#stat one dirctory
stat()
{
#init the var
sh_num=0
txt_num=0
#check the .sh file
for name in `ls $1`; do
suffix=`echo $name | awk '/\.sh$/{print}'`
if [ -n "$suffix" ]; then
#if [ $suffix ]; then
sh_num=$(expr $sh_num + 1)
continue
fi
suffix=`echo $name | awk '/\.txt$/{print}'`
if [ -n "$suffix" ]; then
#if [ $suffix ]; then
txt_num=$(expr $txt_num + 1)
fi
done
echo ".sh file:\t"$sh_num
echo ".txt file:\t"$txt_num
}
recur()
{
for d in $*; do
if [ -d "$d" -a -x "$d" ];then
echo "${PWD}/$d"
stat "${PWD}/$d"
cd "$d"
recur `ls`
cd ..
fi
done
}
#input check
if [ ! -d "$1" ]; then
echo "Usage: ./menu.sh dir"
echo "The directory must be exist"
exit 0 ;
fi
#save the pwd
PWD=`pwd`
cd $1
recur `ls $1`
#restore the pwd
cd $PWD
|
阅读(1142) | 评论(0) | 转发(0) |