Counting Lines of Code

Counting Lines of Code

Posted on Thursday, June 4, 2009

I've recently been asked to count the number of lines of code in a project at work and assumed that this would be easy to do. It turns out that it isn't as as simple as you might think because the Unix word count command 'wc' doesn't allow for counting lines in files in subdirectories.

Fortunately, thanks to a few nifty Unix commands and some helpful hints on the web, I was able to get the answer to the problem which is the following command:


for file in `find . -name \*.php -type f`; do cat $file; done | wc -l

In this example, I'm using *.php to recursively count the number of lines in PHP files but the same approach will work on other file types too such as HTML or JavaScript.

Armed with this command, I was able to establish that my project has 67,000 lines of PHP which seemed like a lot until I did the same on Pixaria and found it 116,000 lines of code..!


Comments for this article

blog comments powered by Disqus

Recent Entries

Offline Until Monday February 6th
Sunday, January 29, 2012

Pixaria Opposes SOPA and PIPA
Wednesday, January 18, 2012

Pixaria Software Ltd.
Tuesday, January 3, 2012

Pixaria 3.7 Now Available
Monday, January 2, 2012

Active Directory support coming to Pixaria AssetDeck
Sunday, December 4, 2011

Follow Pixaria on Twitter
Sunday, November 20, 2011

Pixaria Gallery 3.6 Now Available
Monday, November 14, 2011

Pixaria Gallery 3.5 Now Available
Monday, October 17, 2011

Updated Translations Coming Soon
Wednesday, September 28, 2011

Pixaria 3.4 Now Available
Saturday, September 10, 2011