Community-driven coverage of elementary OS — news, guides & forums
Dark abstract low-poly geometric landscape with layered triangular facets in deep navy, charcoal, and muted teal, illuminated by a soft electric-blue glow near the horizon

News roundups, tutorials, application guides, and forums — built by users, for users of the elegant Linux distribution.

elementary weekly
#20
Latest roundup · 18 Apr 2015
Freya Release
Final
Covered in weekly #19 & #20
Forum Topics
Active
Installation, customization & more

Automatic Trash And Temporary File Cleanup In Elementary OS

A tidy home folder makes elementary OS feel faster and easier to manage, particularly on laptops with smaller solid-state drives. Files sent to the Trash still occupy storage, while temporary data can accumulate after software updates, browser sessions, failed downloads, and large application jobs.

The safest approach is to separate three different jobs: emptying the desktop Trash, cleaning temporary directories, and removing application caches only when you understand what they contain. These locations have different purposes, retention rules, and risks.

For Australian users, storage can disappear quickly when an NBN connection is used for large game downloads, virtual machines, ISO images, or offline streaming. People relying on a mobile hotspot may also keep several copies of installers and media to avoid downloading them again.

elementary OS already provides sensible foundations through Files, GLib, and systemd. With a small amount of configuration, you can create an automatic cleanup routine that retains useful files for a reasonable period and avoids touching personal documents, browser profiles, or system directories indiscriminately.

Know What The Trash And Temporary Folders Do

When you delete a file through Files, elementary OS normally moves it into the per-user Trash rather than removing it immediately. The usual locations are ~/.local/share/Trash/files for the discarded content and ~/.local/share/Trash/info for metadata describing the original path and deletion time.

This behaviour gives you a recovery option. Open Files, select Trash in the sidebar, and restore an item if it was removed accidentally. Emptying the Trash is different from deleting one visible file: it removes every item currently held there, including files you may have forgotten about.

Temporary data follows a separate model. /tmp is intended for short-lived system and application files, while /var/tmp is designed for temporary information that may need to survive a reboot. Your user runtime directory, commonly referenced by $XDG_RUNTIME_DIR, is managed by the session and should be left to the operating system.

Cache directories also deserve care. A cache is usually reproducible data, such as thumbnails, package downloads, or web resources, but “usually” does not mean “always”. Removing a cache can sign you out of an application, force a lengthy redownload, or discard offline content. Automatic cleanup should therefore target known temporary locations first.

Check Storage Before Changing Anything

Start with the graphical Storage settings if your elementary OS release provides them, then inspect individual directories from Terminal. The following commands show the size of your Trash and common temporary locations without deleting anything:

du -sh ~/.local/share/Trash 2>/dev/null
sudo du -sh /tmp /var/tmp 2>/dev/null
df -h /

The du command measures directory contents, while df reports free space on the filesystem. A large Trash directory is generally straightforward to handle. A large /tmp directory deserves more investigation because an active installer, archive extraction, or video export may still be using it.

To find unusually large files in your home directory, use Files’ search tools or a command such as:

find "$HOME" -xdev -type f -size +1G -printf '%s %p\n' 2>/dev/null | sort -n

Review results before removing anything. A multi-gigabyte Linux ISO may be useful for repairing a family computer in Adelaide, while an old copy of the same installer may be pointless. On a refurbished laptop bought through an Australian second-hand marketplace, identifying large recovery images can free considerably more space than blindly deleting caches.

Never run a recursive removal command against /, /usr, /etc, or a path copied from an untrusted website. Administrative commands deserve extra caution because a small path error can affect the entire installation.

Use Built-In Cleanup For A Simple Routine

The most conservative manual option is to open Files, choose Trash, review its contents, and select Empty Trash. This keeps the decision visible and is a good monthly habit for a desktop used for documents, photos, and downloads.

For a command-line equivalent, many current elementary OS installations support:

gio trash --empty

This empties the current user’s desktop Trash. Test the command without scheduling it first, and remember that it does not provide an age-based review step. If someone in the household deletes a tax document or a project folder, the recovery window ends when this command runs.

Temporary directories are normally managed by systemd’s temporary-file facility. You can inspect the active policy with:

systemd-analyze cat-config tmpfiles.d/tmp.conf

On Ubuntu-based systems, the policy commonly gives /tmp a shorter lifetime than /var/tmp, but the exact settings can vary by release and package configuration. Apply the existing cleanup rules manually with:

sudo systemd-tmpfiles --clean

This command follows configured age limits rather than indiscriminately deleting every file. It is safer than using sudo rm -rf /tmp/*, which can interfere with running applications and can remove files that were created only moments earlier.

Create Age-Based Automatic Cleanup

For a user-level Trash policy, systemd-tmpfiles can clean files older than a chosen age. Create a configuration directory and open a new rule:

mkdir -p ~/.config/user-tmpfiles.d
nano ~/.config/user-tmpfiles.d/trash.conf

Add these lines:

d %h/.local/share/Trash/files - - - 30d
d %h/.local/share/Trash/info  - - - 30d

The 30d value means entries older than 30 days are eligible for removal. Thirty days gives you a useful recovery period while preventing years of deleted files from consuming space. If the computer has a small 128 GB drive, 14 days may be reasonable; if it stores valuable work, 60 or 90 days may be preferable.

Run the user cleanup process to test the configuration:

systemd-tmpfiles --user --clean

Some releases may not have an active user systemd manager or may behave differently with user tmpfiles configuration. If the command reports an unsupported option or does not clean the expected location, use a user systemd timer instead. The timer method is more explicit and can also run a script that records what happened.

Trash metadata and discarded files are maintained in separate directories, so age-based rules can leave an orphaned .trashinfo file or remove metadata before its matching content. This is normally harmless, but it explains why a full Trash review can occasionally show unusual entries. Trash folders on removable drives are separate and may use paths such as .Trash-1000; the home-directory rule will not clean them.

Schedule A Safer User-Level Timer

A timer is useful when you want cleanup to happen weekly without granting a script full administrator privileges. Create a script:

mkdir -p ~/.local/bin ~/.config/systemd/user
nano ~/.local/bin/clean-user-trash

Use this content:

#!/usr/bin/env bash
set -euo pipefail

trash="$HOME/.local/share/Trash"
find "$trash/files" -mindepth 1 -maxdepth 1 -mtime +30 -exec rm -rf -- {} +
find "$trash/info"  -mindepth 1 -maxdepth 1 -mtime +30 -type f -delete

Save it and make it executable:

chmod 700 ~/.local/bin/clean-user-trash

The -mtime +30 condition limits deletion to entries whose modification time is older than 30 days. -- protects against names beginning with a dash, while -mindepth 1 prevents the directory itself from being removed. This script is deliberately restricted to your own Trash.

Create the service:

[Unit]
Description=Remove old files from the user Trash

[Service]
Type=oneshot
ExecStart=%h/.local/bin/clean-user-trash

Save it as ~/.config/systemd/user/clean-user-trash.service, then create the timer:

[Unit]
Description=Weekly user Trash cleanup

[Timer]
OnCalendar=weekly
Persistent=true

[Install]
WantedBy=timers.target

Save that as ~/.config/systemd/user/clean-user-trash.timer, then enable it:

systemctl --user daemon-reload
systemctl --user enable --now clean-user-trash.timer
systemctl --user list-timers clean-user-trash.timer

The Persistent=true setting allows the job to run after the computer was off when the scheduled time passed. Check the service log with journalctl --user -u clean-user-trash.service if you need to diagnose a failed run.

Location Typical purpose Sensible action Main warning
~/.local/share/Trash/files Deleted personal files Retain for 30–60 days, then remove Emptying ends easy recovery
~/.local/share/Trash/info Trash metadata Clean with matching Trash policy May contain orphaned records
/tmp Short-lived system and application data Use systemd-tmpfiles policy Active programs may still need files
/var/tmp Longer-lived temporary data Keep the distribution’s configured age Some jobs expect it across reboots
$XDG_RUNTIME_DIR Current login session data Let the session manager handle it Do not manually purge it
Browser and app caches Rebuildable or semi-persistent data Clean selectively and manually May remove sessions or offline data

Avoid Common Cleanup Mistakes

Do not treat every large directory as disposable. Package-manager caches can speed up reinstalls, thumbnail caches can rebuild slowly, and application data stored under ~/.config or ~/.local/share may include settings, databases, accounts, or locally created content.

A common error is to run a command copied from a forum without checking whether it applies to elementary OS. For example, a command that removes /var/cache/apt/archives may be acceptable in a tightly managed environment, but it offers little benefit if the real space consumer is Steam, Flatpak runtimes, downloaded virtual machines, or a folder of duplicate videos.

Flatpak applications can store data under locations such as ~/.var/app. Do not delete those directories as if they were ordinary caches. If a Flatpak was removed and its unused data remains, inspect it first and use the application’s documented removal process. The same principle applies to Snap data if Snap packages are installed.

Privacy matters when cleaning shared or donated equipment. Australian privacy obligations, including the Privacy Act 1988 and the Australian Privacy Principles for covered organisations, do not turn an ordinary Trash cleanup into certified data destruction. Deleted files may remain recoverable on some storage media, and automatic deletion is not a substitute for securely erasing a drive before selling or recycling a laptop.

Be particularly careful on computers used for work, healthcare, education, or small business. An automatic 30-day policy may conflict with an organisation’s retention requirements. Conversely, leaving client exports, identity documents, or downloaded forms in Trash for years creates unnecessary exposure.

Keep The Routine Practical In Australia

A weekly user-level Trash timer works well for a personal elementary OS laptop, especially when the machine is regularly connected to home NBN in Brisbane, Perth, or Melbourne. Schedule it for a time when the computer is likely to be on, and use Persistent=true so missed runs are caught up later.

Mobile broadband deserves a different storage strategy. Australians in regional areas, renters with limited internet options, or students tethering through a phone may intentionally keep installation images and offline maps. Automatic cleanup should focus on genuinely disposable Trash and temporary files, rather than deleting every large download simply because it is old.

Australian electricity costs and warm weather can also influence scheduling. A weekly cleanup that runs briefly while the computer is already in use is preferable to a resource-heavy scan every night. The process described here uses filesystem age checks and should normally finish quickly, even on an older laptop.

Before disposing of a device through an e-waste collection service, remove personal accounts and securely erase sensitive storage according to the drive type and your risk level. Australia’s state and territory e-waste arrangements differ, so check the relevant council or approved recycling provider rather than placing electronics in a regular household bin. Automatic Trash cleanup is everyday housekeeping; preparing a device for resale or recycling requires a separate, deliberate process.

The essential rule is simple: let systemd manage system temporary directories, give personal Trash a clear retention period, and inspect anything outside those locations before deleting it. A modest weekly policy keeps elementary OS storage under control while preserving the recovery time and privacy awareness that matter most.

Browse the News Archive
Latest Updates

From the elementary weekly series

Low-poly faceted abstract render in dark charcoal and electric blue tones, suggesting a news bulletin or announcement
elementary news

elementary weekly #20

The first week with the final Freya release — community reactions, tips, and early impressions gathered in one roundup.

Abstract low-poly geometric scene in midnight blue and soft cyan, conveying a live broadcast or event atmosphere
elementary news

elementary SPECIAL

A live Hangouts event with the elementary OS founders, held on 11 April 2015, discussing the Freya final release.

Low-poly faceted render in deep navy and muted teal with subtle amber highlights, suggesting a tutorial or guide
Tips and Tricks

Timeshift Guide

How to use Timeshift — the intuitive system restore utility for elementary OS — to recover from configuration mishaps.

Explore

Topics & Resources

Dive into guides, application recommendations, and community discussions covering every aspect of elementary OS.