How to Delete Empty Files in Ubuntu Directory Tree
This article provides a direct method for removing all zero-byte files from a specific directory and its subdirectories in Ubuntu. It covers the essential terminal command using the find utility, explains each flag for clarity, and outlines safety steps to verify files before permanent deletion. Follow these instructions to clean up your file system efficiently.
To delete all empty files in a directory tree, open your terminal and use the following command:
find /path/to/directory -type f -empty -deleteReplace /path/to/directory with the actual path where
you want to start the search, such as . for the current
folder or /home/user/documents.
Here is what each part of the command does: * find: The
utility used to search for files. * -type f: Ensures only
files are targeted, ignoring directories. * -empty: Matches
files that have a size of zero bytes. * -delete: Removes
the matched files immediately.
It is highly recommended to perform a dry run before deleting
anything. Remove the -delete flag and replace it with
-print to see which files will be affected:
find /path/to/directory -type f -empty -printReview the list carefully. Once you confirm these are the files you
intend to remove, run the original command with the -delete
flag. Always ensure you have backups of important data before executing
bulk deletion commands.