My current solution would be find
, but this takes far too long when there are more than 10000 results. Is there no f
This is my countfiles
function in my ~/.bashrc
(it's reasonably fast, should work for Linux & FreeBSD find
, and does not get fooled by file paths containing newline characters; the final wc
just counts NUL bytes):
countfiles ()
{
command find "${1:-.}" -type f -name "${2:-*}" -print0 |
command tr -dc '\0' | command wc -c;
return 0
}
countfiles
countfiles ~ '*.txt'