find -empty: Find Empty Files and Dirs
find -empty matches regular files with zero bytes and directories with no entries.
Empty files and directories often litter a workspace after a failed step. -empty finds them so you can prune the noise.
What it does
find -empty matches a regular file whose size is zero or a directory that contains no entries. Combined with -type it targets one or the other, for example -type d -empty to clean up empty output directories.
Common usage
find . -type f -empty
find . -type d -empty -delete
find dist -emptyOptions
| Element | What it does |
|---|---|
| -empty | Match zero-byte files or empty directories |
| -type f -empty | Only empty regular files |
| -type d -empty | Only empty directories |
| -delete | Combine to remove the empties |
In CI
find . -type d -empty -delete is a tidy way to drop leftover empty output directories after a build. Run it repeatedly if removing children creates new empty parents, or rely on the -depth behavior of -delete to cascade in one pass.
Common errors in CI
-empty is a GNU extension that is also supported by BSD/macOS find, so it is portable on common runners. If it appears unsupported on a very minimal BSD, replace it with -size 0 for files. Mixing -empty with -delete on a deep tree may need a second pass if parents become empty.