我要统计一下我一个c工程的代码行数
wc -l *.c
只能统计当前文件夹,子文件夹搞不定
find . -name '*.c' | wc -l
统计出来的是文件数量。。。
怎么才能统计一个文件夹下边的所有c文件行数,包括子文件夹里的
PHP中文网2017-04-17 11:06:56
Just pass the file name to the wc command
find . -name '*.c' | xargs wc -l {}\;
ringa_lee2017-04-17 11:06:56
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
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
-------------------------------------------------------------------------------
PHP中文网2017-04-17 11:06:56
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.
大家讲道理2017-04-17 11:06:56
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}'
高洛峰2017-04-17 11:06:56
Using shell is the easiest. . . It can also be like this. cat find . -name *.c
| wc -l
PHP中文网2017-04-17 11:06:56
find . -name "*.[ch]*" | xargs wc -l | grep "total" | awk '{ print $1}'
阿神2017-04-17 11:06:56
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