Useful Snippets

Welcome!


This blog is used to collect useful snippets related to Linux, PHP, MySQL and more. Feel free to post comments with improvements or questions!

RSS Latest posts from my personal blog


Most viewed posts


Subscribe to RSS feed


Counting lines of code (LOC) in PHP projects

Stanislav KhromovStanislav Khromov

CLOC is a great utility that counts lines of code in your project.

It also shows you how many files, blank lines and comment lines you have. Great stuff!

For Debian / Ubuntu you can install CLOC via:

apt-get install cloc

For CentOS/RHEL you can install CLOC via:

yum install cloc

Running it is simple:

cloc folder/

Here’s an example run, which also excludes a folder (.idea) from appearing in the stats.

cloc chibi-php-github/ --exclude-dir=.idea
      32 text files.
      32 unique files.
      96 files ignored.

http://cloc.sourceforge.net v 1.58  T=1.0 s (26.0 files/s, 1932.0 lines/s)
-------------------------------------------------------------------------------
Language                     files          blank        comment           code
-------------------------------------------------------------------------------
PHP                             26            284            715            933
-------------------------------------------------------------------------------
SUM:                            26            284            715            933
-------------------------------------------------------------------------------

To exclude multiple folders, simply comma-separate them:

cloc chibi-php-github/ --exclude-dir=.idea,vendor,node_modules

CLOC needs no configuration and works for many languages!

Web Developer at Aftonbladet (Schibsted Media Group)
Any opinions on this blog are my own and do not reflect the views of my employer.
LinkedIn
Twitter
WordPress.org Profile
Visit my other blog

Comments 0
There are currently no comments.