方法一:
Ubuntu下利用shell脚本、管道和find命令统计当前目录下一个后缀名结尾的文件一共有多少行
$ find . -type f -name "*.java" | xargs cat | wc -l 70981
(注:里面包含了空白行)
方法二:
Ubuntu下另外一个统计方法:采用cloc.
它可以很方便统计项目中不同语言的代码行数,操作上非常简单。
(1)安装
$ sudo apt-get install cloc
(2)进入到需要统计的目录执行
$ cloc .
(注意后面有个“.“ 表示当前目录)
得到结果
498 text files.
497 unique files.
8 files ignored.
http://cloc.sourceforge.net v 1.56 T=9.0 s (54.4 files/s, 8238.6 lines/s)
-------------------------------------------------------------------------------
Language files blank comment code
-------------------------------------------------------------------------------
Java 470 8750 20998 41298
SQL 1 13 3 2338
XML 19 49 51 647
-------------------------------------------------------------------------------
SUM: 490 8812 21052 44283
-------------------------------------------------------------------------------
原文链接:https://blog.csdn.net/xiprofile/article/details/37597223