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.
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
s3cmd
Python command line client for uploading, retrieving and managing data in Amazon S3 and S3-compatible storage such as Google Cloud Storage and DreamObjects.
PathPicker
Command-line tool (fpp) that parses piped output for file paths, shows a curses selector, and opens the selected files in $EDITOR or runs a command on them.
beets
Command-line music library manager that catalogs collections and autocorrects tags using MusicBrainz, Discogs, and Beatport, extensible through Python plugins.
ranger
Console file manager with VI key bindings, multi-column display, and file preview capabilities
xplr
Terminal-based file explorer with Lua scripting, keyboard controls, and plugin system for command-line integration
add a badge to your README
Maintain trash-cli? Show that it's featured on trmn. The badge links back to this page.
[](https://www.trmn.sh/tools/andreafrancia-trash-cli?utm_source=badge)<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>