Calculate how many lines in code project
There are many times that you need to calculate total number of lines in your coding project. Here’s an example of how to do this on Linux or Unix like systems:
find . -type f -name '*.js' -exec wc -l {} \; | awk '{ SUM += $0} END { print SUM }'
Note the example above shows how to calculate total lines of all the JavaScript (.js) files. If your project are using other languages, you need to change the suffix part following -name switch. For example, to calculate the number of lines in all java files, it should be:
find . -type f -name '*.java' -exec wc -l {} \; | awk '{ SUM += $0} END { print SUM }'
To calculate the number of lines in all cpp files, you just use ‘*.cpp’ in the name suffix part.
If there are multiple languages used in your project, you need to calculate the number of lines separately for each language, then add them together.