Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

counting source code lines in python project

How do I calculate the number of lines written in a project containing multiple sub dirs in a python project. for example a dir structure is like

A  
 \ <*some files here*>\  
  B  
   \ <*some files here*>\ ... and so on...
like image 648
daydreamer Avatar asked Nov 24 '25 09:11

daydreamer


1 Answers

You could use the find utility in linux.

On the command prompt:

$ find <project_directory_path> -name '*.py' | xargs wc -l

This will give you the count of all files ending with .py in the project_directory and finally the total. (I am assuming you just want the count of .py files)

If you just want the total and nothing else, you could use:

$ find <project_directory_path> -name '*.py' | xargs wc -l | tail -1
like image 94
varunl Avatar answered Nov 26 '25 23:11

varunl



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!