In Linux systems, empty directories often accumulate over time — leftovers from removed applications, failed builds, or cleanup scripts that didn't fully run. Fortunately, there is a simple, reliable one-liner to locate them.
The Command
find . -type d -emptyWhat This Command Does
find .Starts searching from the current directory and all subdirectories recursively.-type dLimits the results to directories only.-emptyMatches directories that contain no files and no subdirectories.
The result is a clean list of directories that are truly empty.
Example Output
./logs/old
./tmp/cache
./build/outputEach line represents a directory with zero contents.
Practical Variations
Ignore Permission Errors
Useful when scanning system paths or shared directories:
find . -type d -empty 2>/dev/nullRemove Empty Directories (Careful)
If you're confident and want automatic cleanup:
find . -type d -empty -deleteThis permanently deletes directories. Always review results first.
Run on a Specific Path
find /var/www -type d -emptyWhy This Works Well
- No scripting required
- Works on GNU/Linux and macOS
- Fast even on large directory trees
- Safe by default (read-only)
When to Use It
- Cleaning build artifacts
- Maintaining servers or CI workspaces
- Auditing filesystem clutter
- Pre-deployment sanity checks
Summary
The command:
find . -type d -emptyis the simplest and most effective way to locate empty directories and subdirectories in Linux. It's safe, portable, and ideal for both manual inspection and automated maintenance workflows.