Trash management
To prevent accidental deletion of files, you can use a trash can. To ensure compatibility between multiple applications, you can use software (CLI, GUI or Library) that follow the FreeDesktop.org's Trash specification.
Trash directories
in the specification).Trash creation
Some GUI file managers, such as GNOME Files and Dolphin, natively support moving files into the trash. There are also some CLI tools:
-
glib2 provides a
gio trash file...
command to move files into the trash, whilegio trash --empty
empties the trash. See also "trash" in gio(1) § COMMANDS. The gvfs package is required to fully support trash management through thegio trash
command. -
kde-cli-tools provides a
kioclient5
command that can be used askioclient5 move file trash:/
to movefile
to the trash. - trash-cli — A command-line interface implementing FreeDesktop.org's Trash specification.
- trashman — A Python trash manager.
- rmtrash — trash-put made compatible to GNUs rm and rmdir.
- trash-d — drop-in replacement for GNU rm, focusing on compatibility and with much better performance, written in D.
- trashy — simple, fast, and featureful alternative to rm and trash-cli written in rust
- gtrash — A Featureful Trash CLI manager written in Go
- rmw (ReMove to Waste) — A configurable CLI trash management utility that can purge your trash after X days and integrate with FreeDesktop.org's Trash specification, written in C
Trash space usage management
To prevent the trash can from using too much space, you can empty it yourself, or have a pruning policy
Software list
- autotrash — Tool to automatically purge old trashed files
Criteria
- make sure to have at least x MB of free space
- delete files older than x days
- only empty if you have less than x MB of free space (useful in combination of previous criteria)
- maximum trash can size
- file size
- file type
- original path
Automation
To automate emptying the trash can, you can use cron, systemd/Timers, or inotify (using inotify, only new deletion would trigger the trash can automation)
Troubleshooting
Unable to find or create trash directory
External drives
/etc/fstab
might not be set correctly. Note that ID
must be replaced by your own user id by $ id
.
/etc/fstab
# <device> <dir> <type> <options> <dump> <fsck> UUID=75667752-8b06-11ea-bc55-0242ac130003 /externalDrive ntfs-3g defaults,uid=ID 0 1
Make sure that the root directory of the drive contains ~/.Trash-1000/{expunged,files,info
} and set relevant read permissions for the directory and sub-directory.