Count Lines of Code with Cloc

While it might seem a little of a mundane task, counting the lines of code in your programming projects can be a useful thing to do, and provides you with interesting statistics.

Cloc is a Perl script written to allow you to do just that. Download the script, and then from a command line, you simply pass it a directory of source code, or a single file if you wish.

$ perl cloc.pl /path/to/code

Cloc is more than just a tool for counting the number of lines in the file, it is more clever than that. Cloc detects the programming language if it can, and then shows you the number of blank lines, code and comments of each file.

With a single file, Cloc might give output similar to this:

Cloc screenshot 1

As I've mentioned, however, Cloc's real strong point is when you point it at a directory or several directories of source code.

Cloc screenshot 2

Quite frankly, I think this is a pretty indispensable tool for any programmer interested in getting statistics on their code, especially when you want an overview of the whole project.

Cloc can be downloaded from here. The Perl script version should work on any operating system where you have a working installation of Perl. Windows users can download the pre-built exe as well.

Avatar for peter Peter Upfold - http://peter.upfold.org.uk/

Peter Upfold is a technology enthusiast from the UK. Peter’s interest in Linux stems back to 2003, when curiosity got the better of him and he began using SUSE 9.0. Now he runs Linux Mint 9 on the desktop, runs a CentOS-based web server from home for his personal website and dabbles in all sorts of technology things across the Windows, Mac and open source worlds.

Home » Articles »

Discussion: Count Lines of Code with Cloc

  1. # Posted on 06 July 2008 at 06:29 AM

    [...] en FOSSwire «Anterior | Temas SimilaresGoogle Web [...]



  2. Vladimir (guest)

    # Posted on 25 June 2011 at 08:13 AM

    Thx a lot,Peter! With best regards from russia! This script makes me happy : )



Home » Articles » Count Lines of Code with Cloc