How to Find Empty Directories in Ubuntu Linux (find -empty)

The Cluttered Filesystem

Over time, an Ubuntu Linux server can accumulate hundreds of empty directories. This often happens when automated deployment scripts run but fail to copy their payloads, or when uninstalling software leaves behind empty configuration folders. While these empty directories consume almost zero disk space, they massively clutter your directory tree and make manual navigation frustrating. Finding and removing these folders by hand is nearly impossible. Instead, you can instruct the Linux search engine to mathematically evaluate the contents of every folder and isolate the empty ones.

Using the find Command with -empty

The Linux find command utilizes the -empty flag in conjunction with -type d (directory) to perfectly isolate folders that contain zero files or subfolders.

  1. Open your Terminal application (Ctrl + Alt + T) or log into your server via SSH.
  2. To search the /var/www/ directory specifically for empty folders, type the following command exactly:
    sudo find /var/www/ -type d -empty
  3. Press Enter and provide your administrator password.

Cleaning Up Automatically

Once you verify the output list and confirm that you want to delete those specific folders, you can leverage the search engine to automate the cleanup. By appending the -delete flag to the end of your command (sudo find /var/www/ -type d -empty -delete), the search engine will instantly and permanently erase every empty directory it finds. Note: The -delete flag acts immediately and without confirmation, so always run the standard search first to review the targets before executing the deletion.

Get the best tech tips delivered straight to your inbox.

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