How to Easily Delete Empty Files in a Directory on Mac

How to Delete All Empty Files in a Directory on Mac

If you’ve accumulated empty files over time in a directory on your Mac, they can clutter up your system and take up unnecessary space. Fortunately, there’s a simple way to delete all empty files in a directory using a Terminal command. Here’s a quick guide to help you clean up your directories with ease.

Step 1: Open Terminal

First, open Terminal. You can do this by searching for it in Spotlight (press Cmd + Space and type “Terminal”) or navigating to it in Applications > Utilities > Terminal.

Step 2: Navigate to the Directory

To delete empty files in a specific directory, you’ll need to navigate to that directory in Terminal. Use the cd command (change directory) followed by the path to the folder.

For example:

cd /path/to/your/directory

Replace /path/to/your/directory with the actual path to your target directory. You can also drag and drop the folder into the Terminal window after typing cd to automatically fill in the path.

Step 3: Run the Command to Delete Empty Files

Once you’re in the correct directory, run the following command:

find . -type f -empty -delete

Here’s what each part of this command does:

  • find .: This initiates a search starting from the current directory (indicated by the .).
  • -type f: This restricts the search to files, ignoring directories.
  • -empty: This filters the search to only include empty files.
  • -delete: This deletes each file that meets the criteria.

Caution: This action is irreversible, so double-check that you’re in the correct directory before hitting Enter.

Bonus Tip: Verify Before Deleting

If you want to see a list of empty files before deleting them, you can run the command without the -delete option:

find . -type f -empty

This will output a list of empty files within the directory. If you’re satisfied with the list, you can then re-run the command with -delete to remove them.

Wrapping Up

Using this command can be a quick way to tidy up your directories and keep your system organized. This command not only works on Mac but is also compatible with most Unix-based systems, including Linux.

Cleaning up empty files may not seem like a significant task, but it can contribute to better file organization and overall system cleanliness. Happy organizing!