How to Automatically Empty the Trash on Linux with Autotrash

To automatically empty the Linux desktop Trash, install Autotrash and schedule it to remove items after a retention period you choose. For example, a daily timer with a 30-day rule keeps recently deleted files available for recovery and permanently removes older entries. Autotrash deletes files from the Trash; it does not clean ordinary folders such as Downloads.

Most Linux desktop environments use the freedesktop Trash layout. The home Trash is usually ~/.local/share/Trash, with deleted items in files and their deletion-date records in info. Autotrash reads those records to decide which items have passed the age limit. Anything it purges is permanently deleted, so choose the number of days deliberately.

1. Install Autotrash with pipx

Autotrash is a Python command-line utility. Its current project instructions recommend pipx, which installs command-line Python apps in isolated environments. Install pipx from your distribution’s repository, then install Autotrash as your regular desktop user.

  • Ubuntu or Debian: sudo apt install pipx
  • Fedora: sudo dnf install pipx
  • Other distributions: follow the pipx installation guide or your distribution’s package instructions.
Linux terminal showing pipx installation commands for Ubuntu or Debian
Install pipx from the system package repository, then add Autotrash with pipx.

Install the application:

pipx install autotrash

If the shell cannot find autotrash, add pipx’s application directory to your path and open a new terminal:

pipx ensurepath
command -v autotrash

The second command prints the executable’s full path. Keep it handy if you use cron, which may not load the same shell path as an interactive terminal. You can also inspect the installed options with autotrash --help.

Linux terminal commands for locating the Autotrash executable and opening its help
Confirm the command is available and check the options supported by your installed version.

2. Choose how long to keep deleted files

The -d option sets the minimum age in days. A 30-day policy is a reasonable example, but choose a longer period if you may need more time to recover files:

autotrash -d 30

Running that command immediately purges entries older than 30 days; it is not a preview. The scheduled setup below uses the same rule once per day. Before running Autotrash manually, check the Trash in your file manager and make sure you are comfortable permanently deleting the eligible items. To use a different retention period, replace 30 in the commands below with your chosen number.

3. Schedule a daily cleanup with systemd

On a Linux distribution with systemd, Autotrash can create a per-user service and timer. Run these commands from the account whose Trash you want to maintain. Do not use sudo for this setup: a user timer is independent for each account and keeps the cleanup scoped to that user.

autotrash -d 30 --install
systemctl --user enable --now autotrash.timer

The first command creates the daily service configuration with the 30-day rule. The second enables the timer and starts it now. The Autotrash project documentation also describes how to start or disable this user timer.

Terminal commands for creating and enabling the daily Autotrash systemd timer
Create the daily Autotrash service, then enable its user timer.

4. Check the timer and turn it off

To see the next scheduled run, use:

systemctl --user list-timers autotrash.timer

For the service state and recent run details, use systemctl --user status autotrash.service. If the timer is missing, confirm that the --install command completed and that you ran it as the same account. A user timer depends on that account’s systemd user manager being available; if you need cleanup while logged out, check your distribution’s user-service policy or use its cron service instead.

Linux terminal command to list the Autotrash systemd timer
Use systemctl to inspect the Autotrash timer schedule.

To stop future automatic cleanup, disable the timer:

systemctl --user disable --now autotrash.timer

Use cron instead of systemd

If you prefer cron or your system does not provide user systemd timers, edit your own crontab with crontab -e and add a daily entry. Replace the example path with the exact path printed by command -v autotrash:

@daily /home/your-user/.local/bin/autotrash -d 30

Save the crontab and confirm the entry with crontab -l. Cron runs only while the machine and cron service are available; a powered-off computer may miss a run. Use either the systemd timer or cron for a given account, rather than scheduling both.

Cleaning more than one Trash directory

By default, the command targets the current user’s home Trash. If you intentionally want to include other Trash locations, Autotrash documents the -t option; its example combines it with a 30-day limit as autotrash -td 30. This can widen the cleanup scope. Check autotrash --help for the installed version and ensure the scheduled account has the access you intend before enabling it. On a multi-user computer, separate per-user timers are the clearest way to keep each person’s retention policy independent.

Linux does not have one universal desktop switch for automatically emptying every Trash implementation. Autotrash works with desktop environments that use the freedesktop Trash records. See the freedesktop Trash specification for the file and metadata layout, and the crontab manual for schedule syntax.

Leave a Comment

How to Share Files Over Bluetooth on Linux with Blueman

How to Share Files Over Bluetooth on Linux with Blueman

Send and receive files over Bluetooth on Linux with Blueman. Install OBEX support, pair devices, choose a file, accept transfers, and fix common issues.

How to Connect to Servers with GNOME Files

How to Connect to Servers with GNOME Files

Connect GNOME Files to SSH/SFTP, FTP, SMB, WebDAV, or NFS with the correct server URI, sign-in details, and fixes for common connection errors.

How to Connect to Servers in Linux With the KDE Dolphin File Manager

How to Connect to Servers in Linux With the KDE Dolphin File Manager

Open SFTP, SSH, SMB, FTP, NFS, and WebDAV locations in Dolphin, sign in safely, transfer files, and save network folders for later.

How to Use a PS4 Controller on Linux: USB, Bluetooth, and Steam

How to Use a PS4 Controller on Linux: USB, Bluetooth, and Steam

Connect a DualShock 4 to Linux by USB or Bluetooth, then check controller detection and configure Steam Input only when a game needs it.

How to Speed Up the Fedora Linux App Installer

How to Speed Up the Fedora Linux App Installer

Use DNF5 parallel downloads to reduce RPM install waits in GNOME Software, then tell when mirror or Flatpak delays need a different fix.

How to Use iCloud on Linux Through Your Web Browser

How to Use iCloud on Linux Through Your Web Browser

Access iCloud on Linux in a current browser. Learn how to sign in, use iCloud Drive and other web apps, and understand the limits of browser access.

How to Back Up the Linux Bootloader to a USB Drive

How to Back Up the Linux Bootloader to a USB Drive

Save GRUB settings, boot files, and UEFI entry details to removable storage, then use rescue media to repair the correct boot path safely.

How to Install and Set Up Bitwarden on Linux

How to Install and Set Up Bitwarden on Linux

Install Bitwarden on Linux with the right DEB, RPM, Snap, Flatpak, or AppImage package, then sign in and set a secure vault timeout.

How to Change the Screensaver on Xfce: Choose a Theme and Set the Idle Time

How to Change the Screensaver on Xfce: Choose a Theme and Set the Idle Time

Pick a screensaver theme in Xfce, preview it, choose when it starts, and configure automatic locking in the separate Lock Screen tab.

How to Disable the Screensaver in GNOME Shell

How to Disable the Screensaver in GNOME Shell

Stop GNOME Shell from blanking or locking your display automatically. Change Power and Screen Lock settings, or use Caffeine for a temporary keep-awake toggle.