How to Find Empty Files and Directories in Ubuntu Using the find Command

The Clutter of Zero-Byte Files

As you run scripts, compile code, and install applications on an Ubuntu Linux server, the system naturally generates hundreds of temporary files. Often, if a script fails mid-execution or a logging process crashes, it leaves behind “zero-byte” files—completely empty files that contain absolutely no data. While they don’t consume hard drive space, thousands of empty files can bloat your file system index, slow down backup processes, and make it incredibly frustrating to search through a directory. To keep your server’s file structure clean and organized, you should periodically locate and delete these empty remnants.

Using the find Command with -empty

The standard Linux find command includes a highly specific flag designed exactly for this purpose: -empty.

  1. Open your Terminal application (Ctrl + Alt + T) or log into your server via SSH.
  2. Navigate to the directory you want to clean up (e.g., cd /var/log/).
  3. To simply generate a list of every empty file and directory, type the following command:
  4. sudo find . -empty
  5. Press Enter.

Refining and Automating the Process

The command above will list everything that is empty. However, you usually want to treat files and folders differently.

  • Find only empty files: Add the type flag for files. sudo find . -type f -empty
  • Find only empty directories: Add the type flag for directories. sudo find . -type d -empty

Once you are absolutely confident that the list generated is safe to delete, you can append the -delete flag to the end of the command to tell Ubuntu to permanently destroy the zero-byte files without asking for confirmation:

  1. sudo find . -type f -empty -delete

Warning: Always run the command without the -delete flag first to double-check the list before pulling the trigger, as system configuration folders sometimes rely on empty files acting as structural placeholders.

Get the best tech tips delivered straight to your inbox.

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