Ubuntu Technical

Ubuntu technical problems and solutions reference, a modern cookbook.

Tag Archives: code

Using bash to count number of lines of code in a project

As the title suggests, here are 2 ways of counting the lines of code you just wrote, in whatever language. My examples will look into .java files.

To make the result include commented line, in other words, every line in the files.

cd {project location}
find . -type f -name '*.java' -exec cat {} \; | sed '/^\s*$/d' | wc -l

The second command excludes commented out lines. It only counts code, pure code.

cd {project location}
find . -type f -name '*.java' -exec cat {} \; | sed '/^\s*#/d;/^\s*$/d;/^\s*\/\//d' | wc -l


Flattr this

%d bloggers like this: