Using the command:
wc -l + `find . -name \* -print`
You can get the total number of lines of all files inside a folder.
But imagine you have some folders (for example li开发者_如何转开发braries), which you don't want to count their lines because you didn't write them.
So, how would you count the lines in a project excluding certain folders?
cloc has always been a great friend whenever I need to count lines of src-code. Using 2.6.29 linux kernel as an example:
$ cloc .
26667 text files.
26357 unique files.
2782 files ignored.
http://cloc.sourceforge.net v 1.50 T=168.0 s (140.9 files/s, 58995.0 lines/s)
--------------------------------------------------------------------------------
Language files blank comment code
--------------------------------------------------------------------------------
C 11435 1072207 1141803 5487594
C/C++ Header 10033 232559 368953 1256555
Assembly 1021 35605 41375 223098
make 1087 4802 5388 16542
Perl 25 1431 1648 7444
yacc 5 447 318 2962
Bourne Shell 50 464 1232 2922
C++ 1 205 58 1496
lex 5 222 246 1399
HTML 2 58 0 378
NAnt scripts 1 85 0 299
Python 3 62 77 277
Bourne Again Shell 4 55 22 265
Lisp 1 63 0 218
ASP 1 33 0 136
awk 2 14 7 98
sed 1 0 3 29
XSLT 1 0 1 7
--------------------------------------------------------------------------------
SUM: 23678 1348312 1561131 7001719
--------------------------------------------------------------------------------
With find
, you can also "negate" matching conditions with !
. For example, if I want to list all the .java
files in a directory, excluding those containing Test
:
find . -name "*.java" ! -name "*Test*"
Hope this helps!
Edit:
By the way, the -name
predicate only filters file names. If you want to filter paths (so you can filter directories), use -path
:
find . -path "*.java" ! -path "*Test*"
you could always exclude them by listing out the files using regular expressions, for example,
*.txt will include only txt files and so on...
I made an NPM package specifically for this usage, which allows you to call a CLI tool and providing the directory path and the folders/files to ignore
it goes like:
npm i -g @quasimodo147/countlines
to get the $ countlines
command in your terminal
then you can do
countlines . node_modules build dist
精彩评论