Skip to content

Instantly share code, notes, and snippets.

@jeandat
Last active October 16, 2015 12:21
Show Gist options
  • Save jeandat/bf39824c659a7bc1ff1e to your computer and use it in GitHub Desktop.
Save jeandat/bf39824c659a7bc1ff1e to your computer and use it in GitHub Desktop.
Count lines number in a project

Count lines number in files

By combining the power of git and bash, we can have in an instant an estimation of lines number in a project.

For instance to count lines number in versionned perl files:

$ git ls-files | egrep ".*(driver|core).*pl$" | xargs wc -l
  • git ls-files will only return files versionned which is a first interesting filter.
  • egrep pattern will allow us to filter precisely a portion of project (by file extension, path, etc.)
  • wc -l will count lines by file and make the sum.

Found here : http://stackoverflow.com/questions/4822471/count-number-of-lines-in-a-git-repository

Warning, do not use grep -e which accepts only one pattern per -e. egrep is more useful.

Generate that kind of output :

$ git ls-files | egrep ".*(driver|core).*pl$" | xargs wc -l
    1090 cgi-bin/coreOVECC.pl
    2460 cgi-bin/driver.pl
    3550 total
@jeandat
Copy link
Author

jeandat commented Oct 16, 2015

3550 lines of code in two files, what a pleasure :(

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment