本博文为原创,遵循CC3.0协议,转载请注明出处:http://blog.youkuaiyun.com/lux_veritas/article/details/9097927
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
最近想统计一下研究生两年以来的代码量,于是写了个简单的bash脚本。
目录结构相对简单,脚本也没有过多测试,贴出来大家玩:
#!/bin/sh
# specify the path after the executable bash script
# eg. ./count_lines my_path
# this will count current dir if parameter is null
COUNT=0
func_count()
{
for file in `ls $1` ; do
DIR=$1/$file
if [ -f $DIR ] ; then
COUNT=$(($COUNT+`sudo wc -l $DIR | cut -d " " -f 1`))
elif [ -d $DIR ] ; then
func_count $DIR
fi
done
}
if [ ! -n "$1" ]; then
func_count .
else
func_count $1
fi
echo "the total num is: $COUNT"
本文介绍了一个用于统计指定路径下所有文件代码行数的Bash脚本。该脚本能递归地遍历目录,并支持统计各种类型的源代码文件。
350

被折叠的 条评论
为什么被折叠?



