ThisCalculator

Everyday

Delete Old Files From Trash Linux: 4 Ways

Updated · Standard formula, shown below

Delete Old Files From Trash Linux: 4 Ways

To delete old files from the trash in Linux, you can use the file manager’s empty trash option, the rm command on the trash directory, or the trash-cli tools. This article explains each method, how the trash system works, and how to recover files before they are permanently gone.

How the Linux Trash System Works

Unlike Windows, Linux does not have a single trash folder. Each filesystem partition and each user account can have its own trash directory, following the FreeDesktop.org Trash specification. When you delete a file from a file manager like GNOME Files, KDE Dolphin, or Xfce Thunar, it is moved to ~/.local/share/Trash/files/ on the same partition. Metadata about the original location and deletion date is stored in ~/.local/share/Trash/info/ as a .trashinfo file.

If you delete a file from a different mounted drive (e.g., an external USB stick), the trash folder is created at the root of that drive, often as .Trash-1000 (where 1000 is your user ID). This design allows files to be trashed without copying them across partitions, which would be slow.

Method 1: Using the File Manager GUI

The simplest way to empty the trash is through your desktop environment’s file manager. The exact steps vary slightly, but the principle is the same:

  1. Open your file manager (Files, Dolphin, Thunar, etc.).
  2. Look in the sidebar for a “Trash� or “Bin� entry and click it.
  3. Press Ctrl+A to select all files, or choose specific ones.
  4. Right-click and select “Delete� or “Empty Trash� from the context menu.

Some file managers also have a dedicated “Empty Trash� button in the toolbar when you are viewing the trash. This permanently removes all files in that trash folder. If you only want to remove files older than a certain date, the GUI does not offer a built-in filter, so you would need to use the command line.

Method 2: Using the rm Command Directly

For users comfortable with the terminal, you can delete the contents of the trash folder directly. The main trash location is ~/.local/share/Trash. To see what is inside:

ls -la ~/.local/share/Trash/files/

To delete everything in the trash permanently:

rm -rf ~/.local/share/Trash/files/*
rm -rf ~/.local/share/Trash/info/*

Be careful: the -rf flag forces deletion and recurses into directories. There is no confirmation and no way to undo this. Also, this only clears the trash for your current user on the current partition. If you have trashed files on other mounted drives, you need to locate their trash folders (e.g., /mnt/usb/.Trash-1000) and repeat the process.

Method 3: Using trash-cli for More Control

The trash-cli package provides command-line tools that respect the trash specification and offer safer deletion. Install it with your package manager, e.g., sudo apt install trash-cli on Debian/Ubuntu, or sudo dnf install trash-cli on Fedora. Key commands:

  • trash-list – shows all trashed files with their original paths.
  • trash-empty – empties the trash (use trash-empty 30 to delete files older than 30 days).
  • trash-rm pattern – deletes files matching a pattern.
  • trash-restore – interactively restores a file to its original location.

For example, to delete only files that have been in the trash for more than a week:

trash-empty 7

This is the safest command-line method because it uses the metadata in the info files to determine age, and it only affects the trash, not other files.

Method 4: Scheduled Automatic Cleanup

If you want to avoid accumulating old trash, you can set up a cron job or a systemd timer to run trash-empty regularly. For instance, to run it every Sunday at 3 AM, add this to your crontab (crontab -e):

0 3 * * 0 /usr/bin/trash-empty 30

This will delete files older than 30 days every week. Adjust the path to trash-empty if needed (check with which trash-empty). Some desktop environments also have built-in settings for automatic trash cleanup, but they are not universal.

Common Problems and Misconceptions

One common misconception is that emptying the trash frees up space immediately. That is true, but if you have multiple partitions, you must empty the trash on each partition. Another issue is that files deleted from the command line with rm do not go to the trash at all – they are gone immediately. Only file managers and tools that explicitly use the trash API send files to the trash.

If you get a “Permission denied� error when trying to empty the trash, it may be because some files are owned by another user (e.g., from a previous system installation). You can use sudo rm -rf ~/.local/share/Trash/files/* but be aware that this will also delete files that might belong to other users if the trash is shared.

Another problem: the trash folder can become huge if you delete large files. Check its size with du -sh ~/.local/share/Trash. If it is unexpectedly large, it may contain files from a failed deletion or a system crash. In that case, manually inspect the contents before emptying.

Safety and Recovery Considerations

Once you empty the trash, the files are permanently deleted and cannot be recovered through normal means. If you think you might need a file, consider using trash-restore before emptying. For critical data, use a backup solution. If you accidentally empty the trash and need to recover a file, you would have to use file recovery tools like testdisk or photorec, which are not guaranteed to work on solid-state drives due to TRIM.

To avoid accidental permanent deletion, you can configure your file manager to ask for confirmation when emptying the trash. In GNOME Files, go to Preferences → Trash and check “Ask before emptying the Trash�.

Frequently Asked Questions

Does emptying the trash in Linux free up disk space?

Yes, it does. When you empty the trash, the files are unlinked from the filesystem, and the space they occupied becomes available for new data. However, if you have multiple partitions or external drives, you must empty the trash on each one to free space everywhere.

Can I recover files after emptying the trash?

Generally, no. Once the trash is emptied, the file data is no longer referenced and may be overwritten. On traditional hard drives, recovery tools might find remnants, but on SSDs with TRIM, recovery is nearly impossible. Your best bet is to restore files before emptying the trash.

Why is my trash folder so large?

It may contain large files you deleted, or files from other users if the system is shared. Also, if you delete files from a different partition, they might be stored in a separate trash folder on that partition. Check the size with du -sh ~/.local/share/Trash and also look for .Trash-* folders on mounted drives.

What is the difference between rm and sending to trash?

rm permanently deletes files immediately, bypassing the trash. Sending to trash (via file manager or trash command) moves the file to a trash directory, allowing you to restore it later. Use trash (from trash-cli) instead of rm if you want a safety net.

How do I delete only files older than a specific date?

Use trash-empty N where N is the number of days. For example, trash-empty 30 deletes files that have been in the trash for more than 30 days. This uses the deletion date stored in the .trashinfo files.

Is it safe to delete the trash folder manually?

You can delete the contents, but do not delete the Trash directory itself, as some file managers expect it to exist. If you delete the whole folder, the file manager will recreate it when needed, but you might lose track of trashed files. It is safer to use rm -rf ~/.local/share/Trash/* instead.

Related

Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.