I think, therefore I am. I am, therefore I sail

Count lines of code in files recursively

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

Previous

Bash: Recursively adding an extension to all files without extensions

Next

Today’s storage technology is amazing

2 Comments

  1. Ricardo

    This version allows the usage of regular expressions, which may be more flexible than the “find” command global expressions.

    (find . | grep -E “\\.cc|\\.c|\\.h” | tr ‘\n’ ‘\0’ | xargs -0 cat) | wc -l

  2. Tim Sampson

    There’s also some apps in the App Store for this such as SourceCounter and Xloc.

Leave a Reply

Your email address will not be published. Required fields are marked *

Powered by WordPress & Beards