http://exp99.diandian.com/post/2012-06-02/40028807537
使用工具 cloc
cloc (Count Lines Of Code) counts, and computes differences of, comment lines, blank lines, and physical lines of source code in many programming languages.
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 Perl with no dependencies outside the standard distribution of Perl v5.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 OS X, AIX, Solaris, IRIX, z/OS, and Windows.
使用方法:
http://garfileo.is-programmer.com/2010/6/11/lines-counting-using-cloc.18828.html
使用 cloc 统计代码行数
可能大家都知道用 `wc -l` 命令进行代码行数统计,但是它会将代码中的注释、空行所占用的文本行都统计在内。如果想查看一个 tar 包或一个项目目录中“实际”的代码行数并且不愿意自己去写一个脚本来做此类工作,那么可以考虑使用 cloc。
cloc 是一个 perl 脚本,它可以统计很多种编程语言的代码文件中的空行、注释以及实际的代 码行数。
示例 1:统计一个 tar 包中的代码行
$ > cloc small-2.0.tar.gz 42 text files. 41 unique files. 4 files ignored. http://cloc.sourceforge.net v 1.50 T=1.0 s (38.0 files/s, 3451.0 lines/s) ------------------------------------------------------------------------------- Language files blank comment code ------------------------------------------------------------------------------- C 21 435 482 1695 C/C++ Header 8 102 161 275 m4 4 18 4 136 make 4 18 72 29 Bourne Shell 1 2 20 2 ------------------------------------------------------------------------------- SUM: 38 575 739 2137 -------------------------------------------------------------------------------
示例 2:统计项目目录中的代码行数
$> cd m2boxtree $> cloc ./ 68 text files. 65 unique files. 23 files ignored. http://cloc.sourceforge.net v 1.50 T=0.5 s (88.0 files/s, 9258.0 lines/s) ------------------------------------------------------------------------------- Language files blank comment code ------------------------------------------------------------------------------- C 17 611 94 2490 C/C++ Header 14 230 301 381 Bourne Shell 10 56 155 252 make 2 3 0 25 Python 1 4 4 23 ------------------------------------------------------------------------------- SUM: 44 904 554 3171 -------------------------------------------------------------------------------
先安装brew
http://blog.csdn.net/jijunyuan/article/details/39672291
安装命令如下:
curl -LsSf http://github.com/mxcl/homebrew/tarball/master | sudo tar xvz -C/usr/local --strip 1
当brew安装成功后,就可以随意安装自己想要的软件了,例如cloc,命令如下:
sudo brew install cloc
卸载的话,命令如下:
sudo brew uninstall cloc
查看安装软件的话,命令如下:
sudo brew search /apache*/ /apache*/是使用的正则表达式,用/分割。