How to Find and Delete Empty Directories in Ubuntu (find -delete)

The Clutter Eradication Challenge

When uninstalling complex software packages or migrating large web applications on an Ubuntu Linux server, the process frequently leaves behind hundreds of nested, completely empty directories. These “ghost folders” do not consume significant disk space, but they severely clutter your filesystem structure, making future navigation and backup indexing unnecessarily slow. Manually navigating through a massive directory tree to identify and run rmdir on every empty folder is mathematically inefficient. You must automate the search and destruction process simultaneously.

Using the find Command with -empty and -delete

The Linux find command allows you to chain the -empty flag with the highly destructive -delete flag to instantly purge unneeded structural nodes.

  1. Open your Terminal application (Ctrl + Alt + T) or log into your server via SSH.
  2. To scan the /var/www/html/ directory and permanently delete every folder that contains absolutely zero files or subdirectories, type the following command exactly:
  3. find /var/www/html/ -type d -empty -delete
  4. Press Enter.

Execution Order Safety

The syntax order is absolutely critical. First, -type d filters the results so the engine is strictly looking at directories (ignoring empty zero-byte files). Next, -empty confirms that the directory contains absolutely no hidden files or nested folders. Finally, the -delete action executes a permanent removal. If you put -delete before the filters, you will instantly wipe the entire server. This command is an absolute necessity for system administrators maintaining a clean, highly optimized filesystem architecture after major structural migrations.

Get the best tech tips delivered straight to your inbox.

Join thousands of readers mastering Apple, Google, Microsoft, and Linux.