James
James

Reputation: 5403

How can I count all of the lines in all of the files in the current directory and child directories?

I'm trying to figure out how many lines of code have been written for an app. Code is in the current directory and child directories. I'm using ubuntu.

Upvotes: 1

Views: 3926

Answers (2)

tempestSA
tempestSA

Reputation: 149

If you just want the total lines you can use the following command:

find . -name \*.c -o -name \*.h -exec cat {} \; | wc -l

Upvotes: 5

Jim Lewis
Jim Lewis

Reputation: 45045

find . -type f -name \*.c -exec wc -l {} \;  > /tmp/c_counts
find . -type f -name \*.h -exec wc -l {} \;  > /tmp/h_counts

This will produce the wc output for each file with a particular extension, one extension per /tmp file. You could run these results through a simple awk script to get the grand total, if that's what you need.

Upvotes: 1

Related Questions