4 ms·
You'll want to quote .java so the shell doesn't interpret it as a glob, and find doesn't use GNU style flags. You can also pass wc the filenames directly like t
by sjs 15y ago
You'll want to quote .java so the shell doesn't interpret it as a glob, and find doesn't use GNU style flags. You can also pass wc the filenames directly like this:
wc -l $(find . -name '*.java')
- jedbrown 15y agoThat has different semantics (it prints one line per file) and can have line length limitations. This has the same semantics as the parent's version, but without line length issues. find . -name \*.java -exec cat {} + | wc -l
- X-Istence 15y agoNote that the + may not be portable. I know it doesn't work on older Solaris versions (<10) and HP-UX (from a couple years ago when I last touched it). Also, find may or may not split the files it finds into multiple invocations.
- Karellen 15y agoToo many invocations of "cat" find . -name \*.java -print0 | xargs -0 cat | wc -l Edit: Dammit. Others have already posted this exact version further below. :-(
- tikhonj 15y agoYeah, the flags always get me. For some reason, I've never had issues with the *. It's good to know about passing files to wc directly. I just use M-x find-dired and friends these days for most things, admittedly.