转载:统计项目文件个数或者代码行数的shell
ls -lR|grep "^d"|wc -l //统计文件夹下目录的个数,包括子文件夹里的 ls -lR|grep "^-"|wc -l //统计当前文件夹下文件的个数,包括子文件夹里的 ls -l |grep "^d"|wc -l //统计当前文件夹下目录的个数 ls -l |grep "^-"|wc -l //统计当前文件夹下文件的个数 sed -n '$=' file // 统计文件行数 #!/bin/bash filesCount=0 linesCount=0 function funCount(){ # 排除node_modules、dist目录 exclude=$(echo "$1" | grep -E 'node_modules\b|dist\b') if [[ $exclude = "" ]] then for file in ` ls $1 `; do if [ -d $1"/"$file ];then funCount $1"/"$file else declare -i fileLines fileLines=`sed -n '$=' $1"/"$file` let linesCount=$linesCount+$fileLines let filesCount=$filesCount+1 fi done else echo "排除的目录$exclude" fi; } if [ $# -gt 0 ];then for m_dir in $@ do funCount $m_dir done else funCount "." fi echo "filesCount = $filesCount" echo "linesCount = $linesCount"