Easy way of counting effective lines of code from the console

When looking for nifty one-liners on the web that counts the number of non-blank or non commented lines in my code I ran in to CLOC. If you have a thing for working in the console, CLOC is a really nice tool for counting lines of code in a set of folders or archives. If Sonar is available and configured it is excellent but sometimes there might simply be easier to run things quickly and locally from a console, pick your favourite one-liner, tweak the sed OR just use CLOC.

Could not be easier
Download and put the executable in the path and run for a given folder,

$ cloc <the folder with my code/archive-file>

and you will get the output

http://cloc.sourceforge.net v 1.56  T=43.0 s (35.2 files/s, 7550.3 lines/s)
Language                     files          blank        comment           code
XML                            680          36091              5         149257
HTML                           699          30773              5          79958
Java                           106           3130           4904          16395
Javascript                      18            430            190           2384
CSS                              6            184             47            862
Python                           1              6              5             30
Bourne Shell                     2              2              0              4
DOS Batch                        2              0              0              3
SUM:                          1514          70616           5156         248893

There are many, many flags (http://cloc.sourceforge.net/#Options) that can be used for filtering and tweaking the output, so from now on this is one of the must have tools on my machine.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: