Search code examples
linuxbashfindls

How to list non-empty directories with the command find or ls?


It is necessary to list non-empty directories in a subdirectory Trying to use

find . ! -type d -empty -print

but it doesn't work,


Solution

  • You're asking for "things that are not directories and are empty", which includes all zero-length files (and would exclude all directories). You want "things that are directories and are not empty", so:

    find . -type d ! -empty -print