shell脚本练习(查询某目录下的所有文本文件的个数,和行数)

Ichjns

关注

阅读 133

2022-09-14


————————————————

#!/bin/bash

if [ $# -lt 1 ];then
echo "at least one path."
exit 1
fi

if ! [ -e "$1" ];then
echo "file does not exist"
exit 2
elif ! [ -d "$1" ];then
echo "file is not directory"
exit 3
else
fileCount=0;
lineCount=0;
for i in $1/*;do
if echo "$(file $i)"|grep "ASCII text" &>/dev/null;then
fileCount=$[$fileCount+1]
lineCount=$[$lineCount + $(cat $i|wc -l)]
fi
done
echo "text file count :$fileCount"
echo "text lien count:$lineCount"
fi

 

精彩评论(0)

0 0 举报