I have a directory of files and I want to find a list of files who has more than 2 lines.
I know I can use wc -l to test each file, but how do I wrap it up in bash?
Sorry for the newbie question, new to bash.
You can use this find
command:
find . -type f -exec bash -c '[[ $(wc -l < "$1") -gt 2 ]] && echo "$1"' _ '{}' \;
Using xargs
and awk
:
$ find . -type f | xargs wc -l | awk '$1 > 2'
If you are in a git repository and want to count only tracked files, you can use following command:
$ git ls-files | xargs wc -l | awk '$1 > 2'
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