Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to count lines of code?

I tried rake stats but that seems highly inaccurate. Perhaps it ignores several directories?

like image 472
AnApprentice Avatar asked Oct 17 '10 19:10

AnApprentice


People also ask

How do you count lines in a script?

The wc command is used to find the number of lines, characters, words, and bytes of a file. To find the number of lines using wc, we add the -l option. This will give us the total number of lines and the name of the file.

How can you tell how many lines of code a project has?

Cloc can be used to count lines in particular file or in multiple files within directory. To use cloc simply type cloc followed by the file or directory which you wish to examine. Now lets run cloc on it. As you can see it counted the number of files, blank lines, comments and lines of code.

How do you count lines of code in Python?

Use readlines() to get Line Count This is the most straightforward way to count the number of lines in a text file in Python. The readlines() method reads all lines from a file and stores it in a list. Next, use the len() function to find the length of the list which is nothing but total lines present in a file.


1 Answers

I use the free Perl script cloc. Sample usage:

phrogz$ cloc .      180 text files.      180 unique files.                                                 77 files ignored.  http://cloc.sourceforge.net v 1.56  T=1.0 s (104.0 files/s, 19619.0 lines/s) ------------------------------------------------------------------------------- Language                     files          blank        comment           code ------------------------------------------------------------------------------- Javascript                      29           1774           1338          10456 Ruby                            61            577            185           4055 CSS                             10            118            133            783 HTML                             1             13              3            140 DOS Batch                        2              6              0             19 Bourne Shell                     1              4              0             15 ------------------------------------------------------------------------------- SUM:                           104           2492           1659          15468 ------------------------------------------------------------------------------- 
like image 124
Phrogz Avatar answered Oct 06 '22 11:10

Phrogz