trash-cli

Command-line interface to the freedesktop.org trashcan: trash, list, restore, and empty files using the same trash as KDE, GNOME, and XFCE.

install

trash-cli moves files and directories to the freedesktop.org trashcan instead of deleting them, recording the original path, deletion date, and permissions. Because it uses the same trashcan as KDE, GNOME, and XFCE, items trashed from the command line or from scripts show up in those desktop environments, and the reverse also holds. On the home partition, trashed files go to ~/.local/share/Trash/.

It provides five commands: trash-put (trash files and directories), trash-list (list trashed files with deletion timestamps), trash-restore (restore a trashed file), trash-rm (remove individual files from the trashcan by pattern, e.g. trash-rm '*.o'), and trash-empty (empty the trashcan). trash-restore shows a numbered list and prompts for a selection. It accepts comma-separated entries and ranges such as "0-2, 3", and an --overwrite option replaces existing files. trash-empty accepts a number of days to remove only items trashed more than that many days ago, and -f skips the confirmation prompt.

The README documents a cron recipe for auto-deleting items older than 30 days (a daily trash-empty 30), and shows how to create a top-level /.Trash directory. It advises against aliasing rm to trash-put, because the semantics differ: for example, trash-put does not require -R for directories. Bash, zsh, and tcsh completions can be generated with --print-completion after installing the completion extra. Btrfs volumes are not supported. trash-cli is aimed at Linux and macOS command-line users and script authors who want recoverable deletion.

Installation

# via Homebrew
brew install trash-cli
# via apt (Debian/Ubuntu)
sudo apt install trash-cli
# via pipx
pipx install trash-cli

Alternatives & related tools

add a badge to your README

Maintain trash-cli? Show that it's featured on trmn. The badge links back to this page.

Featured on trmn
Markdown
[![Featured on trmn](https://www.trmn.sh/badge/andreafrancia-trash-cli.svg)](https://www.trmn.sh/tools/andreafrancia-trash-cli?utm_source=badge)
HTML
<a href="https://www.trmn.sh/tools/andreafrancia-trash-cli?utm_source=badge"><img src="https://www.trmn.sh/badge/andreafrancia-trash-cli.svg" alt="Featured on trmn" height="20"></a>