0
点赞
收藏
分享

微信扫一扫

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

Ichjns 2022-09-14 阅读 133


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

#!/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 条评论