0

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.

Community
  • 1
  • 1
Robert
  • 10,126
  • 19
  • 78
  • 130

3 Answers3

3

to avoid using xargs

find \( -name '*.php' -o -name '*.js' -o -name '*.html' \) -exec wc -l {} +
  • \( \) grouping so that all results are given to wc command
  • add as many -o -name as required within \( \)
  • use iname instead of name to ignore case of filenames
  • by default, find works on current directory

Reference:

Community
  • 1
  • 1
Sundeep
  • 23,246
  • 2
  • 28
  • 103
2

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

gotnull
  • 26,454
  • 22
  • 137
  • 203
1

Here is a one liner. It uses find regex option to find for matching extensions, and wc --files0-from=- parameter to get file list from standard input

find -regex '.*\(php\|js\|css\|html?\)' -printf '%p\0' |wc -l --files0-from=-
Adam
  • 17,838
  • 32
  • 54