People always ask me how many lines I wrote for my thesis research project. I really don’t keep track of details like that – I just concentrate on accomplishing the goals and getting results. But I figured that I should find this out so that I can just blurt out a number when someone asks and be done with it. Then I realized that wc does not recurse into subdirectories.
My code is neatly divided into packages, sub-packages and etc… So it took me a minute or two to figure out how to run a recursive word count. Here it is:
wc -l `find . -name *.java`
This will print out the name of each file along with the line count, and then give you a grand total on the last line.
If anyone is curious the number of lines is 5284 as of today. It should be more because I haven’t implemented all the features that I wanted yet (not sure if I ever will but, you know…). The longest file has 801 lines, and the shortest one has 49. Now stop asking. :mrgreen:
If you want to exclude a directory from the listings use prune:
wc -l `find . -wholename './lib/*' -prune -o -name '*.java -print`
This will count the lines in all the files except those in ./lib/
[tags]wc, word count, recursive word count, lines, lines of code, thesis[/tags]