trashd
A recycle bin for Linux that works everywhere — interactive shells, scripts, cron jobs, services, and the desktop.
Deleted the wrong file with rm? With trashd there is nothing new to learn: keep typing rm as usual and the file lands in the trash instead of disappearing. Bring it back with one command:
$ rm notes.txt
$ trash undo
That is the whole idea. The rest of this page explains how to install trashd, every command it provides, how to tune it, and — for the curious — exactly how it intercepts deletions without slowing your system down.
[!NOTE]
trashd is Linux-only. It needs no desktop environment: the desktop trash and the command-line trash are the same trash, so files you delete in a terminal show up in GNOME Files, Dolphin, Thunar, and other file managers (and vice versa).
Contents
What is trashd?
On Windows and macOS, deleting a file usually moves it to a Recycle Bin or Trash folder first. You get a grace period to change your mind. On a Linux command line, rm file.txt is forever — one typo, one wrong glob (rm *.txt in the wrong directory), one script bug, and the file is gone.
trashd closes that gap. Once installed, deletions are redirected to a standard trash folder instead of being carried out immediately:
| You do this |
Without trashd |
With trashd |
rm report.pdf |
Gone forever |
Moved to trash — trash restore report.pdf brings it back |
A script runs rm -rf build/ |
Gone forever |
Moved to trash as one entry — trash undo brings it back |
Python runs os.remove(path) |
Gone forever |
Moved to trash (the program does not need to know trashd exists) |
| A compiled or static binary unlinks a file |
Gone forever |
Moved to trash when the command runs under trashd-exec |
How is this different from similar tools?
trash-cli gives you a separate trash-put command. It only protects you when you remember to use it — existing scripts that call rm are unprotected. trashd protects rm itself, plus programs that never call rm at all.
safe-rm blocks deletions of listed paths. It does not give you a restorable trash.
- Shell aliases (
alias rm='rm -i') only exist in your interactive shell. They do nothing for cron, scripts, find -delete, or other programs. trashd works below the shell.
trashd protects you at four independent layers (a PATH shim, an LD_PRELOAD hook, a kernel-level seccomp supervisor, and an audit daemon). You do not need to understand them to use trashd — How it works explains them in plain language later. The short version: whichever way a program tries to delete a file, at least one layer is likely to catch it and move the file to trash instead.
What trashd is not
- It is not a backup system. Trashed files still live on the same disk. If the disk dies, they die with it. Keep real backups of anything irreplaceable.
- It is not undeletion. Files that bypass trashd (see Safety, limits, and honest fallbacks) and files purged from trash are gone.
- It does not change file-manager behaviour. Your desktop already trashed files correctly; trashd makes the command line share that same trash.
See it in action
$ echo "important draft" > report.txt
$ rm report.txt # looks normal — but the file was trashed, not deleted
$ trash ls
2026-10-22 14:30 16 B /home/you/report.txt report.txt.20261022143000
$ trash undo # oops-proof: restore the last thing you deleted
Restored: /home/you/report.txt
$ rm -rf old-project/ # directories work too, as a single trash entry
$ trash ls
2026-10-22 14:31 2.1 MB /home/you/old-project old-project.20261022143100
$ trash restore old-project # bring it back by name
$ trash status # how much is in the trash right now?
$ trash empty # permanently delete everything in trash (asks first)
Programs are covered too — no code changes, no wrapper needed for ordinary scripts:
$ python3 -c "import os; os.remove('cache.db')" # caught by the LD_PRELOAD layer
$ trash ls
2026-10-22 14:32 48 KB /home/you/cache.db cache.db.20261022143200
Quick start
You need
- A Linux system (any distribution; see Compatibility for kernel notes — the core
rm protection works on every kernel).
- Rust 1.100.0 or newer (
cargo) to build from source. Check with cargo --version. Install Rust from rustup.rs if you do not have it.
sudo access for the system-wide install.
[!TIP]
Short on time? Run the four commands below, open a new terminal, and skip to Everyday use. You can come back for configuration and internals later.
Install
git clone https://github.com/faratech/trashd.git
cd trashd
sudo ./install.sh
Run the installer with sudo from your normal (non-root) account that owns the checkout. It compiles as your user in a private staging area under $TMPDIR (default /tmp; if that is mounted noexec, run sudo TMPDIR=<dir> ./install.sh with a root-owned directory that allows running programs) — never as root — using the committed Cargo.lock, then installs:
- The
trash command and helpers into /usr/local/bin/ and /usr/local/lib/trashd/.
- An
rm shim that shadows the real rm on your PATH (the real rm is kept safely at /usr/local/lib/trashd/real/rm).
- The
LD_PRELOAD library, registered system-wide in /etc/ld.so.preload so scripts, cron jobs, and services are covered too.
- A login-shell hook (
/etc/profile.d/trashd.sh) that activates the shim (and, for root shells, kernel-level protection).
- The
trashd audit daemon as a systemd service, plus an optional weekly cleanup timer (shipped disabled — see Keeping trash under control).
- Man pages (
man trash, man trash-ls, …) and shell completions for bash, zsh, and fish.
- A commented starter config at
/etc/trashd/config.toml (nothing is overridden until you edit it).
Start using it
Open a new terminal (or run source /etc/profile.d/trashd.sh in the current one), then verify:
$ rm --version # prints "trashd rm shim …" (the real rm answers `rm --help`)
$ echo hello > ~/demo.txt && rm ~/demo.txt
$ trash ls # demo.txt should be listed (use your home dir: /tmp is never-trashed by default)
$ trash undo # and now it is back
If trash ls shows the file, you are protected. Every rm from now on — in this shell, in scripts, in cron — moves files to trash instead of deleting them.
Uninstall
sudo ./install.sh --uninstall # remove trashd, KEEP everything already in trash
sudo ./install.sh --uninstall --purge # remove trashd AND permanently delete all trash
Uninstalling removes the binaries, the LD_PRELOAD registration (first, so no process is left pointing at a missing library), the shell hook, the systemd service, man pages, completions, and config. By default your trashed files are left exactly where they are — uninstalling a safety net should not destroy the things it caught. Add --purge only if you also want every trash directory (for every user, on every mounted filesystem) emptied for good.
Other install methods (make install, distro package templates, manual copies) are covered in Install options in detail.
Everyday use
Just keep using rm
You do not need to change any habits or scripts. The shim accepts the GNU rm flags you already use:
rm file.txt # moved to trash, not deleted
rm -rf project/ # whole directory moved to trash as one entry
rm -i important.txt # asks before each file (same wording style as GNU rm)
rm -I *.tmp # asks once when removing 3+ files or recursing
rm -v file.txt # verbose: prints "removed 'file.txt'" per entry, like rm
rm -d empty_dir/ # remove an empty directory (refuses a non-empty one, like rm)
rm -- *.txt # names starting with a dash still work after --
Good to know:
- Interactivity matches GNU
rm. -i, -I, --interactive=never|once|always, -f/--force, -r/-R/--recursive, -d/--dir, -v/--verbose, --one-file-system, and --preserve-root (including the refusal to recursively remove /) behave as rm users expect — except the outcome is "moved to trash" instead of "deleted".
- A declined prompt deletes nothing. If you answer "no" at a confirmation prompt, that file stays where it is. Files created inside a directory while you are being asked about it are never swept up: each confirmed subtree is trashed as exactly what you confirmed.
- Very large recursive deletes are planned safely. Before mutating anything, the shim pins the directories it walked (32 MiB planning budget per operand, depth limit 128, one open file descriptor per directory; for the walk it raises its soft open-file limit toward the hard limit, up to 65536, which leaves room for about 21,000 directories). If an operand is too large to plan safely, that operand is refused before anything is removed — never half-trashed.
- In a desktop session (
$DISPLAY or $WAYLAND_DISPLAY set), trashing shows a desktop notification via notify-send when available.
- Bad flags fail safe. An unrecognised
rm flag is an error and deletes nothing. It never falls through to a permanent delete.
The trash command
Use trash to inspect and manage what has accumulated. The five commands most people need:
trash ls # list everything in trash (all disks, newest first)
trash undo # restore the most recently trashed item — the "oops" button
trash restore notes.txt # restore one item by name
trash status # how many items, how much space, per-disk breakdown
trash empty # permanently delete everything in trash (asks for confirmation)
A typical recovery session:
$ trash ls
2026-10-22 09:14 1.2 MB /home/you/Downloads/big-report.pdf big-report.pdf.20261022091400
2026-10-22 11:02 16 B /home/you/notes.txt notes.txt.20261022110200
2026-10-21 18:40 340.0 KB /mnt/data/photos/cat.jpg cat.jpg.20261021184000
$ trash info notes.txt # full details: when, by what command, integrity hash…
$ trash restore notes.txt # back to /home/you/notes.txt
$ trash restore '*.jpg' --all # restore several matches at once
$ trash purge big-report.pdf # permanently delete just this one entry
Handy variations:
trash ls '*.py' # filter by glob (matches file name or full original path)
trash ls --after 2d # only items deleted in the last 2 days
trash ls --before 2026-10-01 # only items deleted before a date
trash ls --json # machine-readable output for scripts
trash find ~/projects # search by original-path substring (glob works too)
trash restore report.txt --to . # restore somewhere else instead of the original place
trash restore report.txt --force # if the destination exists, restore as report.txt.1, .2, …
trash du # biggest items in trash, largest first
trash du -n 10 # top 10 only
trash log # recent trash/restore/purge history
trash log -n 50 # last 50 operations
Choosing the right item:
restore, purge, and info accept a file name, a trash ID, or a glob (for restore). If a name is ambiguous — for example the same file name trashed from two different disks — trashd lists the candidates and asks you to pass one entry's trashed path instead (the trashed_path value from trash ls --json, e.g. ~/.local/share/Trash/files/notes.txt). That path is always unique. File names with non-UTF-8 bytes are matched byte-for-byte.
- If several entries match and you did not pass
--all, trash restore lists the candidates and exits without restoring anything — re-run with an exact trash ID, one entry's trashed path, or --all.
- If the original location is occupied again,
restore refuses rather than overwriting — use --to <dir> to put the file elsewhere, or --force to auto-rename.
Emptying and housekeeping: