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 -empty

What This Command Does

  • find . Starts searching from the current directory and all subdirectories recursively.
  • -type d Limits the results to directories only.
  • -empty Matches 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/output

Each 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/null

Remove Empty Directories (Careful)

If you're confident and want automatic cleanup:

find . -type d -empty -delete

This permanently deletes directories. Always review results first.

Run on a Specific Path

find /var/www -type d -empty

Why 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 -empty

is 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.