How to count lines of your code from your SHELL.

darker - Aug 15 '22 - - Dev Community

So, this one is quite simple, let say, you want to count the lines of code you have inside a project, from a file or a whole directory, how are you going to do it ?

Demo

HOW

This is done with a simple bash function

loc(){
    echo -ne "Lines of Code : ";
    if [ -n "$1" ]; then
        find . -wholename $1 | xargs wc -l;
    else
        find . -name '*' -type f | xargs cat | wc -l;
    fi
}
Enter fullscreen mode Exit fullscreen mode

Basically, it will find files depending on your input and use wc to count lines of your code.

You can then add this in your ~/.bashrc and source before use it or save it in separate shell file that you can call and use when you want !

Thanks for reading, feel free to like and/or subscribe for more 🐼.

. . . . . . . . . . . .
Terabox Video Player