Utility to count the number of lines of code in Python or Bash


Is there a quick and dirty way in either python or bash script, that can recursively descend a directory and count the total number of lines of code? We would like to be able to exclude certain directories though.

For example:

start at: /apps/projects/reallycoolapp
exclude: lib/, frameworks/

The excluded directories should be recursive as well. For example:

/app/projects/reallycool/lib SHOULD BE EXCLUDED
/app/projects/reallycool/modules/apple/frameworks SHOULD ALSO BE EXCLUDED

This would be a really useful utility.

Found an awesome utility CLOC. https://github.com/AlDanial/cloc

Here is the command we ran:

perl cloc.pl /apps/projects/reallycoolapp --exclude-dir=lib,frameworks

And here is the output

Language                      files          blank        comment           code
PHP                              32            962           1352           2609
Javascript                        5            176            225            920
Bourne Again Shell                4             45             70            182
Bourne Shell                     12             52            113            178
HTML                              1              0              0             25
SUM:                             54           1235           1760           3914