DEV Community

Cover image for Finding total lines of code in your project
Mohammad Aziz
Mohammad Aziz

Posted on

Finding total lines of code in your project

You may be a new joiner to your organization or someone who is already working in a firm for many years. One day you're sitting on your chair and suddenly one thought came into your mind.

How many lines of code are in my project? πŸ€”

One challenge could be that you might be relying on external packages, preferably open-sourced, or some code coverage folder might be already present from the last time you have run your test. You can delete them, fair point but then you have to create the coverage or install all of the dependencies again. Only if there is a way adhere my .gitignore rules then the world could have been a little more perfect.

Turns out, there is a way out πŸ’‘

Entering git, like always!

git ls-files | xargs cat | wc -l

Running this command will give you the total number of lines in your project.

There are two parts in this process, well, as you can see there are three parts but you can think the last two commands as singular. The last two commands are there basically to count the number of lines only. The first command is a kind of interesting one which lists all the files that currently present in your repository and excludes the one who is ignored in your .gitignore file. So there you have it.

You can also tweak git ls-files command to check the lines for specific extensions.

Image Courtesy

Discussion (4)

Collapse
mateuszjarzyna profile image
Mateusz Jarzyna

Or use cloc tool :)

Collapse
iaziz786 profile image
Mohammad Aziz Author

Is it pre installed on Linux?

Collapse
mateuszjarzyna profile image
Mateusz Jarzyna • Edited

Not sure, I think no. But git is also not pre installed

Thread Thread
iaziz786 profile image
Mohammad Aziz Author

I think it is preinstalled on most of the Linux distros. Even if it's not then you have to install it anyway πŸ˜„