The Cluttered Filesystem
Over time, an Ubuntu Linux server can accumulate hundreds of completely empty directories. These are often left behind by poorly written uninstallation scripts, temporary caching processes that failed to clean up after themselves, or daily backup routines that created a folder but never actually wrote data into it. While an empty folder takes up virtually zero hard drive space, leaving thousands of them scattered across your filesystem severely clutters your terminal output and makes navigating the server incredibly frustrating. To clean up your architecture, you must be able to locate these ghost directories instantly.
Using the find Command with -empty
The standard Linux find command includes a highly specific flag designed exclusively for locating files and folders that contain absolutely zero bytes of data.
- Open your Terminal application (Ctrl + Alt + T) or log into your server via SSH.
- Determine the directory you want to audit. For this example, we will check the
/var/www/web server folder. - Type the following command exactly as written:
sudo find /var/www/ -type d -empty- Press Enter and provide your administrator password.
Cleaning Up the Ghosts
The command above will generate a raw list of paths (e.g., /var/www/html/old-cache-folder). The -type d flag is critical here, as it ensures the search only returns directories, ignoring empty text files. If you review the list and confirm that all of the directories are indeed useless garbage, you can instruct the find command to instantly delete every single one of them by appending the -delete flag to the end of your search string:
sudo find /var/www/ -type d -empty -delete
This single command will instantly sweep the specified area, permanently erasing the clutter and leaving only the folders that actually contain your valuable data.