linux - 怎么统计一个工程的代码行数
怪我咯
怪我咯 2017-04-17 11:04:56
0
8
970

我要统计一下我一个c工程的代码行数

wc -l *.c

只能统计当前文件夹,子文件夹搞不定

find . -name '*.c' | wc -l

统计出来的是文件数量。。。
怎么才能统计一个文件夹下边的所有c文件行数,包括子文件夹里的

怪我咯
怪我咯

走同样的路,发现不同的人生

reply all(8)
Ty80

Just pass the file name to the wc command

find . -name '*.c' | xargs wc -l {}\;
左手右手慢动作

I once used a tool under Windows, the detailed introduction is here
http://code.google.com/p/boomworks/wiki/SourceCounterCN
It can count data including: number of lines of code, comments, blank lines, file size, etc.
In addition, it also supports the analysis and prediction of manpower, costs, quality indicators, etc. at each development stage of the software development project.

Some are also introduced on the cloc website

  • Sonar
  • Ohcount
  • SLOCCount
  • sclc
  • USC's CODECOUNT
  • loc

cloc Basic Use

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
-------------------------------------------------------------------------------
Ty80

I used to use find wc, now I use cloc.

cloc is a code statistics tool written in perl. Not only supports multiple languages, but also counts blank lines and comment lines.

大家讲道理

You can also use the exec parameter of find, and then add it up with awk.

find -name "*.c" -exec wc -l "{}" ; | awk '{s =$1}END{print s}'
巴扎黑

http://igaojie.com/?p=308

小葫芦

Using shell is the easiest. . . It can also be like this. cat find . -name *.c | wc -l

洪涛

find . -name "*.[ch]*" | xargs wc -l | grep "total" | awk '{ print $1}'

阿神

http://blog.csdn.net/tianmohu...

How to count the number of files in a directory and the total number of lines of code in Linux using the command
The command to know the total number of files with a specified suffix name:
find . -name "*.cpp" | wc -l
Know the total number of lines of code in a directory and the number of lines in a single file:
find . -name "*.h" | xargs wc -l

find . -name "*.c" | xargs grep '^.' | wc -l //Exclude blank lines

wc -l find . -name "*.c " //Note that the find content is wrapped by the symbol below ~

Linux counts the number of files in the folder
The first method:
ls -l|grep “^-”|wc -l
ls -l

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template