next up previous contents
Next: Backing up your files Up: More shell script examples Previous: Counting files greater than   Contents

Counting number of lines of code recursively

The following script counts the total number of lines of code in .c starting in the current directory and continuing in the subdirectories recursively.

#!/bin/sh
# recursive/countlines.sh
total=0
for currfile in `find . -name "*.c" -print`
do
        total=$[total+(`wc -l $currfile| awk '{print $1}'`)]
        echo 'total=' $total
done

If you want to be able to count .h, .cc and .java files as well, modify the argument -name "*.c" to -name "*.[c|h|cc|java]"



Amit Jain 2006-11-20