Count lines of code in files recursively

January 26, 2013

If you are attempting to find a count of the total lines of code in files in a directory recursively from Linux or Mac OS X the following command will do what you want. This particular command prints out all lines contained in any file with a .php extension, then counts the number of lines printed.

( find . -name '*.php' -print0 | xargs -0 cat ) | wc -l