Counting line of code with built-in Linux Find
Published in
2 min readApr 28, 2020
There are a time where we want to estimate how large the code base is
Word count
Let’s see how we count with wc
or ‘word count’ with option -l
means counting line. You can explore more with wc --help
wc -l your_file_name.txt
Listing file
Then we see how to listing all the file -type f
$ find . -type f
then we seeing something is not very relevant like library they import some package manager logging, pictures etc.
So we can specific an extension of file -o
is OR
$ find . -type f -name "*.js" -o -name "*.vue"
this will list all .js
and .vue
file
Combining these two
we will use Linux pipe and xargs
to redirect the output of find
to wc
$ find . -type f -name "*.js" -o -name "*.vue" | xargs wc -l
There you go, now you know about approximate size of the code base.
Codemonday — Web application | Software | IoT