Search code examples
countlanguage-agnosticlines-of-code

Count total number of lines in a project excluding certain folders or files


Using the command:

wc -l + `find . -name \* -print` 

You can get the total number of lines of all files inside a folder.

But imagine you have some folders (for example libraries), which you don't want to count their lines because you didn't write them.

So, how would you count the lines in a project excluding certain folders?


Solution

  • With find, you can also "negate" matching conditions with !. For example, if I want to list all the .java files in a directory, excluding those containing Test:

    find . -name "*.java" ! -name "*Test*"

    Hope this helps!

    Edit:

    By the way, the -name predicate only filters file names. If you want to filter paths (so you can filter directories), use -path:

    find . -path "*.java" ! -path "*Test*"