I'm using bash to count my lines of source in a project. Here's the code:
#!/bin/bash
find . -name '*.java' | xargs wc -l
find . -name '*.xml' | xargs wc -l
I want to exclude files from the ./gen folder. I think it's something to do with 'prune', but I can't figure out how to do it.
EDIT Thankyou to ruakh, but his code wasn't my final solution, I had to make it count the lines again. Here's the finished thing if anybody wants it:
#!/bin/bash
find . -path ./gen -prune -o -name '*.java' | xargs wc -l
find . -name '*.xml' | xargs wc -l
Cloc can be used to count lines in particular file or in multiple files within directory. To use cloc simply type cloc followed by the file or directory which you wish to examine. Now lets run cloc on it. As you can see it counted the number of files, blank lines, comments and lines of code.
The easiest way to count files in a directory on Linux is to use the “ls” command and pipe it with the “wc -l” command. The “wc” command is used on Linux in order to print the bytes, characters or newlines count.
(For example, if you select File, you simply need to browse and select the file you want to exclude. Or if you select the File type option, you only need to enter the extension of the file format to skip during scans.)
Some branches in JS code are typically hard, if not impossible to test. Examples are a hasOwnProperty check, UMD wrappers and so on. Istanbul now has a facility by which coverage can be excluded for certain sections of code. What’s more, 100% coverage isn’t necessary or even reasonable in most cases.
Another class of files/functions you might want to ignore for coverage purposes are test-specific helpers. It doesn’t matter that some of them aren’t run as part of tests, as they’re not the code under test. As with a lot of things in software, it’s about tradeoffs.
So now if you want to list recursively ignored files in directories, we will be using an additional parameter –untracked-files=all, and the command would be: So now we can see that it is listing all the recursively ignored files in directories also.
I couldn't make ruakh's solution work and ended up with the following instead:
find . -not -path '*/gen*' -a \( -name '*.java' -o -name '*.xml' \)
Also found an interesting egrep
option based on GNU find:
find a/ -regextype egrep -not -path '*/gen*' -a -regex '.*(java|xml)$'
In order to count lines in the matched files you can stick xargs cat | wc -l
on the end:
find . -not -path '*/gen*' -a \( -name '*.java' -o -name '*.xml' \) | xargs cat | wc -l
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With