Quick Tip: Lines of Code in sub-folders

Just a quick one- I searched around for a bit longer than I wanted to find out how to find out the number of lines in certain file types in a folder.

The solution was:

find -type f \( -iname "*.java" -o -iname "*.gradle" \) -exec wc -l {} \; | awk '{lines += $1 ; files += 1 ; print  }; END { print "Lines total is: ", lines ," in ", files ," files"}'

As you can see, its a find for all files with names matching the *.java and *.gradle regexs, then a little awk magic to neaten up the out put and display totals at the end.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s