代码规模统计——CLOC.pl工具使用介绍

  作者:zhanhailiang 日期:2013-01-09

因项目汇报,需要统计代码规模。

自然的想法是用Shell来统计各类文件(.php|js|css|html|xml|yaml)的代码规模

> find . -name "*.php" -exec grep -Ev "^$" {} \;|wc -l
75450
> find . -name "*.js" -exec grep -Ev "^$" {} \;|wc -l   
36725
> find . -name "*.html" -exec grep -Ev "^$" {} \;|wc -l  
17830
> find . -name "*.css" -exec grep -Ev "^$" {} \;|wc -l    
4146
> find . -name "*.xml" -exec grep -Ev "^$" {} \;|wc -l   
4349
> find . -name "*.yaml" -exec grep -Ev "^$" {} \;|wc -l 
0

在sourceforge发现统计代码规模的好工具cloc.pl

引用下官方的简介

cloc counts blank lines, comment lines, and physical lines of source code in many
programming languages. Given two versions of a code base, cloc can compute differences
in blank, comment, and source lines. It is written entirely in Perlwith no dependencies
outside the standard distribution of Perlv5.6 and higher (code from some external modules
is embedded within cloc) and so is quite portable. cloc is known to run on many flavors of
Linux, Mac OSX, AIX, Solaris, IRIX, z/ OS, and Windows. (To run the Perlsource version of
cloc on Windows one needs ActiveState Perl5.6.1 or higher, Cygwin, or MobaXTerm with the
Perlplug-in installed. Alternatively one can use the Windows binary of cloc generated with
perl2exe to run on Windows computers that have neither Perlnor Cygwin.)

接下来介绍下如何使用cloc.pl来统计代码规模:

1).下载脚本

> wget http://nchc.dl.sourceforge.net/project/cloc/cloc/v1.56/cloc-1.56.pl

2).给脚本添加执行权限+x

> chmod +x cloc-1.56.pl

3).对项目源码打开

> tar zcvf itravel2.tar.gz itravel2

4).统计代码规模

> ./cloc-1.56.pl itravel2.tar.gz 
     595 text files.
     594 unique files.
    2507 files ignored.

http://cloc.sourceforge.net v 1.56  T=4.0 s (148.0 files/s, 35279.8 lines/s)
-------------------------------------------------------------------------------
Language                     files          blank        comment           code
-------------------------------------------------------------------------------
PHP                            224           4018           9848          62685
Javascript                     118           3570           3083          31469
HTML                           215            574           2557          14820
XML                             19              0             57           4292
CSS                             16            160            473           3513
-------------------------------------------------------------------------------
SUM:                           592           8322          16018         116779
-------------------------------------------------------------------------------

欲知关于cloc.pl脚本详细的信息,请参见http://cloc.sourceforge.net/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值