I wanted to count the lines of code on a project I am working on. From the base directory of the project, I wanted to line count all files ending with .php. I also needed to ignore the directories with test, model/om, cache and plugins. Using grep, find and wc you can do this:
#!/bin/bash
grep -v '^ *$' `find . -iname "*.php" | grep -v model\/om | grep -v \/test | grep -v \/cache | grep -v \/plugins | grep -v \/web | grep -v lib\/OFC` | wc -l
I am at 15645 lines of code, which includes comments. What are you at?
Related posts:
#1 by ploum on March 11, 2009 - 11:15 am
Quote
That’s what I use in my python’s projects :
http://bazaar.launchpad.net/%7Egtg/gtg/trunk/annotate/head%3A/scripts//linecount.sh
#2 by Smurphy on March 11, 2009 - 11:18 am
Quote
21749 for my main php-website, and about 2500 lines per module I wrote on it. 7 Modules ~17500 for the modules
Also all in php
#3 by sharms on March 11, 2009 - 11:32 am
Quote
Smurphy – I am using Symfony as a framework, what are you using? So far symfony has been excellent for me, really made development easy once I got the whole “programming by convention” method down.
#4 by Jeff Schroeder on March 11, 2009 - 12:18 pm
Quote
Another quick tip, try using egrep -v.
jeff@jschroeder2:~$ echo -e ’1\n2\n3\n4′ | grep -v 1 | grep -v 3
2
4
jeff@jschroeder2:~$ echo -e ’1\n2\n3\n4′ | egrep -v ’1|3′
2
4
#5 by Nuno Araujo on March 11, 2009 - 1:45 pm
Quote
You can also use ohcount from OhLoh.
Take a look here: http://labs.ohloh.net/ohcount/
#6 by Marius Gedminas on March 11, 2009 - 3:41 pm
Quote
sudo apt-get install sloccount
#7 by Edward A Robinson on March 12, 2009 - 12:03 am
Quote
grep -v ‘^ *$’ `find . -iname “*.py”` | wc -l
545
#8 by Thibauld Favre on March 12, 2009 - 3:47 am
Quote
Like Marius said, you might want to give sloccount a try. It will give the number of lines of code, an estimation of the development effort and the estimated project cost (based on the COCOMO model) : http://www.allmyapps.com/app/sloccount
#9 by Dom on March 12, 2009 - 4:45 am
Quote
I prefer cloc, based on sloccount but imo better, http://cloc.sourceforge.net/
#10 by Evan Plaice on April 1, 2010 - 8:37 pm
Quote
grep -v ‘^ *$’ `find . -iname “*.cs”` | wc -l
68497
:p. This is, of course, a C# project. Which means, half is probably auto-generated .designer GUI files and the language itself is a lot more verbose.
BTW, thanks for this. I’ve been looking for a simple/easy tool to do LOC counts for a while but most include compiling/installing binaries.
Now… If I could only get one that works in windows too.
#11 by Jamie on September 23, 2011 - 7:06 am
Quote
For my current symfony project, i’m at 31,000 lines of code.
Including the JS (not including jquery, jquery ui etc ) i’m at 7,000
so about 38,000 lines of code for php and js