Congratulations, if you have 10,000 matching files, that line makes you a cat herder. ;-) And a herder of useless cats, to boot…
If you’re going to do that, you can just do
find -name '*.p[lm]' -exec wc -l {} \; | awk '{ sum+=$1 } END { print +sum }'
Moves a bit less data around. It also makes it trivial to count the number of files, as GrandFather’s code does:
find -name '*.p[lm]' -exec wc -l {} \; \ | awk '{ sum+=$1; ++num } END { print sum "lines in" num "files" }'
Nice catch on the glob. :-)
The xargs in mine is quite justified, so I don’t run one process per matched file. The cat is the easiest solution to the problem that if too many files for a single commandline are matched, xargs wc would run the wc multiple times, reporting multiple disjunct totals. This way, xargs runs multiple cats (but very few in total), but wc always run exactly once.
Makeshifts last the longest.
In reply to Re^3: Count file lines in a directory tree
by Aristotle
in thread Count file lines in a directory tree
by GrandFather
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |