Use wc on all subdirectories to count the sum of lines

Jonas Stein picture Jonas Stein · Dec 5, 2012 · Viewed 39.8k times · Source

How can I count all lines of all files in all subdirectories with wc?

cd mydir
wc -l *
..
11723 total

man wc suggests wc -l --files0-from=-, but I do not know how to generate the list of all files as NUL-terminated names

find . -print | wc -l --files0-from=-

did not work.

Answer

gniourf_gniourf picture gniourf_gniourf · Dec 5, 2012

You probably want this:

find . -type f -print0 | wc -l --files0-from=-

If you only want the total number of lines, you could use

find . -type f -exec cat {} + | wc -l