我正在尝试创建一个shell脚本,它将计算一个文件夹中的代码行数。
我得到了这个:
h=find . -type f -name \*.[h]* -print0 | xargs -0 cat | wc -l
m=find . -type f -name \*.[m]* -print0 | xargs -0 cat | wc -l
expr $m + $h但是当我尝试运行它的时候,我得到了这个:
lines-of-code: line 6: .: -t: invalid option
.: usage: . filename [arguments]
0
lines-of-code: line 7: .: -t: invalid option
.: usage: . filename [arguments]
0
+我知道我必须做些什么才能让它在我所在的特定文件夹上运行。这有可能吗?
发布于 2011-09-07 15:31:00
DDIYS (不是你自己)使用cloc。用perl编写的优秀工具,它为您完成计数以及其他工作。它可以识别80多种语言。
输出示例:
prompt> cloc perl-5.10.0.tar.gz
4076 text files.
3883 unique files.
1521 files ignored.
http://cloc.sourceforge.net v 1.50 T=12.0 s (209.2 files/s, 70472.1 lines/s)
-------------------------------------------------------------------------------
Language files blank comment code
-------------------------------------------------------------------------------
Perl 2052 110356 130018 292281
C 135 18718 22862 140483
C/C++ Header 147 7650 12093 44042
Bourne Shell 116 3402 5789 36882
Lisp 1 684 2242 7515
make 7 498 473 2044
C++ 10 312 277 2000
XML 26 231 0 1972
yacc 2 128 97 1549
YAML 2 2 0 489
DOS Batch 11 85 50 322
HTML 1 19 2 98
-------------------------------------------------------------------------------
SUM: 2510 142085 173903 529677
-------------------------------------------------------------------------------发布于 2011-09-07 06:43:27
引用如下命令:
h=$(find . -type f -name *.[h]* -print0 | xargs -0 cat | wc -l)也请看一下计算代码行数的sloccount。你可以用sudo apt-get install sloccount在debian/ubuntu上安装它
发布于 2011-09-07 06:45:13
对于这个特定的问题,我有一个不同的解决方案:
find . -type f -print0 | wc --files0-from=-https://stackoverflow.com/questions/7326969
复制相似问题