How to Automatically Delete Trash and Temporary Files in Ubuntu

When you delete documents, images, or downloads in Ubuntu, the system moves them to the user Trash folder rather than permanently erasing them from your hard drive. Over months of routine computer use, forgotten files accumulating in the Trash—alongside cached temporary system files—can consume gigabytes of precious storage space on your root filesystem. Ubuntu features a built-in automated maintenance utility that systematically purges discarded files after a custom retention period.

Enabling Automated Trash Deletion in Ubuntu Settings

Configuring automatic cleanup takes only a few clicks through Ubuntu’s centralised privacy and housekeeping settings in Ubuntu 22.04 LTS and Ubuntu 24.04 LTS:

  1. Open the Settings application from your dock or application menu.
  2. In the left sidebar, click on Privacy (or Privacy & Security).
  3. In the right pane, click on File History & Trash (or Housekeeping, depending on your GNOME version).
  4. Locate the section titled Trash & Temporary Files.
  5. Toggle on the switch labelled Automatically Delete Trash Content.
  6. Toggle on the switch labelled Automatically Delete Temporary Files.

Ubuntu will now continuously monitor your Trash bin and temporary directory, automatically expelling items once they exceed your specified age threshold.

Setting the Retention Period (7 Days to 30 Days)

Directly beneath the deletion toggles, Ubuntu lets you control exactly how long discarded items remain recoverable before being permanently purged:

  1. In Settings > Privacy > File History & Trash, find the drop-down menu labelled Automatically Delete Period.
  2. Select your preferred retention duration:
    • 1 day: Aggressive cleanup for small SSDs or testing environments.
    • 7 days: Ideal balance for active workstations.
    • 14 days: Two-week grace period.
    • 30 days (Default): Standard safety window to recover accidentally discarded files.

Files that have resided in your Trash longer than your selected period will be automatically and permanently deleted in the background.

Immediate Manual Cleanup Options

If your hard drive is critically full and you cannot wait for the scheduled automatic retention cycle to run:

  • Empty Trash Now: In the same settings panel, click the prominent red button labelled Empty Trash… to purge all deleted files immediately.
  • Delete Temporary Files Now: Click the button labelled Delete Temporary Files… to clear out obsolete application cache files from /tmp.

Automated Housekeeping Options Comparison

Review the automated cleanup parameters to determine the best schedule for your drive capacity:

Setting Target Directory Recommended Schedule Safety Impact
Automatically Delete Trash Content ~/.local/share/Trash/ 14 days or 30 days Allows ample time to restore accidentally deleted user documents.
Automatically Delete Temporary Files /tmp/ and /var/tmp/ 7 days Zero risk to personal data; removes orphaned application scratch files.
File History Retention Recently used file lists 30 days Cleans up “Recent” shortcuts in Nautilus file manager.

Troubleshooting Disk Space Inaccuracies After Emptying Trash

If emptying the Trash does not appear to free up disk space immediately, ensure you check external USB drives or secondary hard disks. Each mounted storage partition maintains its own hidden .Trash-1000 directory. Emptying the main Ubuntu Trash empties trash bins across all currently mounted external partitions.

Automating your Trash and temporary file deletion prevents silent hard drive bloat, keeping your Ubuntu installation fast, clean, and spacious.

Get the best tech tips delivered straight to your inbox.

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