Shell统计代码行数

本博文为原创,遵循CC3.0协议,转载请注明出处:http://blog.csdn.net/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"



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值