File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Linux / UNIX and the fly likes Command to count the lines of code Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » Linux / UNIX
Bookmark "Command to count the lines of code" Watch "Command to count the lines of code" New topic

Command to count the lines of code

divya chamarti
Ranch Hand

Joined: Jul 28, 2006
Posts: 56
If you have to count the lines of code in all Java programs in the directories under your home directory how would you do that?
Please help in finding out the solution
Thanks in advance
David O'Meara

Joined: Mar 06, 2001
Posts: 13459

wc (word count) counts characters, words and lines, so "wc -l" can count the number of lines.
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 15082

And with a command like "find" you can find files, for example all *.java files in a certain directory:

find /home/divya -name *.java

See the man pages for these commands:

man find
man wc

Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
Jeff Rummings
Ranch Hand

Joined: Dec 20, 2007
Posts: 42
Or you can download SLOC count. It supports different languages, easy to use and does everything for you.
I agree. Here's the link:
subject: Command to count the lines of code
jQuery in Action, 3rd edition