Hello, I've implemented a small tool [1] to test whether a directory is empty, and I think it would make a useful addition to GNU coreutils.
There once was a discussion [2] on this mailing list, proposing the extension of `test` with a `-E` flag. AFAICT this led nowhere, although the topic does not show up as rejected feature request [5]. The need to test a directory for emptiness obviously arises occasionally [3], the proposed solutions vary in quality and tend to invoke discussion [4]. IMHO, the number of tools required to implement such a simple test should be 1, but proposed solutions typically involve an invocation of `ls` or `find` and subsequent output processing by `test` or `wc`. These solutions tend to accumulate a degree of complexity that I personally find unsatisfying for the task at hand. Some solutions are more compact and use only shell builtins, e.g., $ if ! (shopt -s failglob dotglob; : *) 2>/dev/null; then echo is empty fi but this may not port nicely to other shells (and has some other caveats). I would find `isemptydir` to fit well with the family of commands like `basename`, `pwd` & Co. — While an addition of theis functionalit to `test` would feel natural, the question of which `test` (the one from coreutils, or a shell builtin) arises. There's no need to reimplement functionality in every shell. I have built `isemptydir` according to my own needs and standards, which may not line up with the culture at GNU/coreutils. But if you're at all interested, then I'm willing to adapt this (e.g., writing a manpage, follow commit log requirements, coding style, etc.). Obviously, this effort only makes sense if adoption is indeed desired. If so, any feedback on the existing codebase would be appreciated. Kind regards Stefan [1]: https://github.com/s5k6/isemptydir [2]: https://lists.gnu.org/archive/html/coreutils/2016-04/msg00024.html [3]: https://www.startpage.com/sp/search?query=linux+shell+test+directory+is+empty&cat=web&pl=opensearch&language=english [4]: https://superuser.com/questions/352289/bash-scripting-test-for-empty-directory [5]: https://www.gnu.org/software/coreutils/rejected_requests.html -- Stefan Klinger, Ph.D. -- computer scientist o/X http://stefan-klinger.de /\/ https://github.com/s5k6 \ I prefer receiving plain text messages, not exceeding 32kB.