[bash] counting lines

It happened that I needed to count all lines of code in all java/jsp files of a project. What faster than bash can do this?

$ find -type f -iregex ‘.+\.j\(sp\|ava\)$’ -print0 | xargs -0 wc -l

However this wont skip the blank lines.

Advertisements

One thought on “[bash] counting lines

  1. Nice shot! I didn’t know about the iregexp option of find command!
    Keep in mind you can also use the -n xargs option to improve performance (for bulk operation, for instance -n 100 reduce numers of executions of “wc”).
    Bye bye

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