How to Find Empty Files and Directories in Ubuntu Linux

The Cluttered Filesystem

Over time, as applications are installed, uninstalled, and updated on an Ubuntu server, they often leave behind hundreds of completely empty text files and vacant directory trees. While a 0-byte file does not consume hard drive space, an excessive amount of them clutters the filesystem, making it difficult to navigate via the terminal and slowing down backup scripts that have to parse thousands of useless paths. Manually clicking through every folder to find them is impossible. Instead, you must instruct the Linux kernel to hunt down files that contain absolutely no data.

Using the find Command with -empty

The Linux find command includes a highly specific -empty flag designed exclusively for this cleanup task.

  1. Open your Terminal application (Ctrl + Alt + T) or log into your server via SSH.
  2. To search a specific directory (like your Downloads folder) for all empty files, type the following command:
  3. find ~/Downloads -type f -empty
  4. Press Enter.
  5. To search for completely empty directories instead, change the type flag to d:
  6. find ~/Downloads -type d -empty
  7. Press Enter.

Automated Deletion (Advanced)

The terminal will print a list of every 0-byte file or empty folder it found. If you want to automatically destroy them without reviewing the list, you can append the delete flag to the command: find ~/Downloads -type f -empty -delete. Warning: Use the delete flag with extreme caution, as some software relies on empty “lock” files to function properly. It is usually best to run the search command first, review the output, and only delete files you know are useless.

Get the best tech tips delivered straight to your inbox.

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