How to count the lines of code in a project?

Jan Grant Jan.Grant at bristol.ac.uk
Tue Dec 23 01:47:30 PST 2003


On Tue, 23 Dec 2003, Zhang Weiwu wrote:

>
> Hello. How to count the number of lines in all *.c file in a directory?
>
> I can think of this on csh:
>
> > grep -c "" `find . -name "*.c"` | sed "s/.*:/e=e+/" > /tmp/countlines.py
>
> And edit the py file, and "e=0" as first line, "print e" as the last
> line, and execute the python script. wooo pretty cool for a newbie like
> me:)
>
> So is there a better method?

Not bad; but when it comes to basic operations on text files, unix has a
surfeit of tools that probably already do what you want. In this case:

	find . -type f -name \*.c -print0 | xargs -0 wc -l



-- 
jan grant, ILRT, University of Bristol. http://www.ilrt.bris.ac.uk/
Tel +44(0)117 9287088 Fax +44 (0)117 9287112 http://ioctl.org/jan/
(ECHOY GRUNTING) (EERIE WHISPERS) aren't subtitles great?


More information about the freebsd-questions mailing list