How to calculate the number of lines in source code
-
13-10-2019 - |
Question
As the title says how i can calculate the total number of lines in a source code folder using bash commands
Solution
Use sloccount
OTHER TIPS
You can just use
find . -name '*.php' | xargs wc -l
Use cloc. It supports about 80 languages.
You could try something like:
find . -name "*.java" -exec cat {} \; | wc -l
My suggestions would be
- Use a
find
command as in Barti's answer to locate all the files - Use
sed
or something to strip out all the comments - Don't do it at all
SLOC is a very, very misleading way to measure software. Bill Gates said it was like estimating the quality of an aircraft by weight, and it may be the only helpful thing he ever said.
This will count empty lines as well, but it's easy. Go to the specific directory you wanna check and do
find . | wc
Already been answered, just giving another way using awk
which you'll definitely have.
cat *.ext | awk 'BEGIN{i=0;} {i++;} END{print "Lines ", i}'
I only also suggest this because it can be easily edited to add patterns (such as comments) for lines that you don't want to count.