How to calculate the number of lines in the source code

As the title says, I can calculate the total number of lines in the source folder using bash commands

+6
bash terminal lines-of-code
source share
7 answers
+19
source share

Use cloc . It supports about 80 languages.

+9
source share

You can just use

 find . -name '*.php' | xargs wc -l 
+9
source share

You can try something like:

 find . -name "*.java" -exec cat {} \; | wc -l 
+2
source share

My suggestions would be

  • Use the find , as in Barti's answer, to find all files
  • Use sed or something to remove all comments
  • Don't do it at all

SLOC is a very, very misleading way to measure software. Bill Gates said it was like evaluating the quality of an airplane by weight, and that might be the only useful thing he ever said.

+1
source share

It will also count empty lines, but it is easy. Go to the specific directory you want to check and execute

 find . | wc 
-one
source share

An answer has already been given by simply adding another way using awk , which you will definitely have.

cat *.ext | awk 'BEGIN{i=0;} {i++;} END{print "Lines ", i}'

I only suggest this because it can be easily edited to add patterns (e.g. comments) for lines that you do not want to read.

-one
source share

All Articles