Robert Rocha Robert Rocha - 4 months ago 15
Bash Question

How to count all the lines of code in a directory recursively using or operator to include several file types

I am reading this answer: How to count all the lines of code in a directory recursively?

But it only works for php files. I want to count recursively including javascript, html, css and php files to get the total number of combined lines of code.

I tried this

find . -name '*.php' |'*.js' | xargs wc -l


But it does not work.

Note: I am using OS X El Capitan.

Answer

Give this a go:

find . -name '*.php' | xargs wc -l

With include files:

find . -name '*.php' -o -name '*.js' | xargs wc -l

To not include certain path:

find . -name "*.php" -not -path "./tests*" | xargs wc -l