Curious to know the size of a project, I was looking for a quick tool to count lines of code. Of the few projects I found, CLOC is what I recommend.


The project is hosted on SourceForge: https://sourceforge.net/projects/cloc/. It has been around since at least 2006. Latest version is 1.64 from just a few days ago, so it is still active. On Ubuntu 15.04, I installed v1.60 with sudo apt-get install cloc.


Run man cloc for a list of all the command-line parameters. Only 2 parameters I needed to use were:

For example, if I wanted to get a summary of a project called "ABC":

cd projects/ABC/ cloc --skip-uniqueness --exclude-dir=build .


Note that blank lines, comments, and source code are split into different columns. Depending on what you plan on doing with the statistics, you may want to combine some of those numbers together. Here is an example of the report created by cloc:

-------------------------------------------------------------------------------- Language files blank comment code -------------------------------------------------------------------------------- C++ 131 4667 1363 22881 C/C++ Header 129 1593 1369 3877 SQL 29 229 208 1604 CMake 45 146 134 381 Bourne Again Shell 2 24 9 44 DOS Batch 2 16 2 30 -------------------------------------------------------------------------------- SUM: 338 6675 3085 28817 --------------------------------------------------------------------------------

So in this example, comments + code is 31902 lines. Then another 6675 blank lines for a total of 38577 lines across 338 files.

Last modified: 2015-06-29
Stéphane Charette, stephanecharette@gmail.com