brew install ajaikn/tap/zap.sh- Copy or symlink
bin/zapinto a directory on your PATH. - To install zsh completions (optional): copy
completions/zsh/_zapinto your zsh completions directory, or sourcezap.plugin.zsh.
Usage: zap [OPTION]... [--] FILE...
or: zap --list
or: zap --restore [OPTION]... [--] FILE...
Put each FILE in the trash. Currently supports macOS and Linux.
-h, --help Show this usage message.
-f, --force Override non-writable files, ignore nonexistent files, and skip untrashable ones.
Like rm -f: files that don't have write permissions are trashed anyway, nonexistent
files are silently ignored, and files that can't be trashed (e.g. because their
directories aren't writable) are reported and skipped while everything else is
still trashed, in which case the exit status is 1. Without --force, this command
refuses to do anything if any of the arguments would fail to be trashed.
-i Prompt before trashing each file.
-I Prompt once before trashing more than three files, or when trashing recursively
(with -r).
--interactive[=WHEN] Prompt according to WHEN: never, once (-I), or always (-i). Without WHEN,
always prompt. By default, prompt before trashing a write-protected file if
standard input is a terminal, and otherwise refuse (unless --force is given).
-i and -I cancel an earlier --force, and --force cancels an earlier -i or -I.
-n, --dry-run Don't actually trash anything; just print what this command *would* do.
This option implies --verbose.
-v, --verbose Be more verbose.
-s, --strategy=STRATEGY Specify which trashing strategy to use.
Can also be specified with the ZAP_STRATEGY environment variable, which this
option supersedes.
-l, --list List trashed files (oldest first) as DELETIONDATE<TAB>ORIGINALPATH.
--restore Restore each FILE (given by its original path) from the trash. If a path was
trashed more than once, restore the most recent one. Refuses to overwrite.
--list and --restore work regardless of strategy. They see freedesktop.org
trash directories, plus items zap trashed with the macOS strategies (recorded
in $XDG_DATA_HOME/zap/info). Items trashed with other tools on macOS aren't
seen.
--one-file-system Refuse to trash a directory that has another filesystem mounted somewhere
inside it (default). Otherwise the mount would go into the trash with it, and
emptying the trash would delete what's on it. (rm skips just those parts, but
zap trashes each FILE whole.)
--no-one-file-system Trash such directories anyway.
--no-preserve-root Don't treat '/' specially.
--preserve-root Refuse to trash '/' (default). With --force, '/' is skipped but the other
arguments are still trashed, and the exit status is 1.
--allow-root Trash files even when running as root (e.g. under sudo). Without this, zap
refuses, since they'd go to root's trash rather than yours. Can also be
enabled with ZAP_ALLOW_ROOT=1. Not needed for the dangerous_* strategies.
-d, --dir Does nothing. For compatibility with rm.
-r, -R, --recursive Does nothing (except with -I). For compatibility with rm.
*Available strategies*
freedesktop (default on Linux) Use the freedesktop.org Trash Specification:
https://specifications.freedesktop.org/trash-spec/1.0/
macos_trash_command (default on macOS >=15.0) Use the built-in macOS /usr/bin/trash command
macos_applescript (default on macOS <15.0) Use AppleScript
macos_mv (default on macOS as root) Use mv to move to ~/.Trash/. Under sudo, that's the
invoking user's trash, like Finder.
gio Use the 'gio trash' command
kioclient Use the 'kioclient move FILE... trash:/' command
trash_cli Use trash-put from trash-cli: https://github.com/andreafrancia/trash-cli
dangerous_rm Use rm
dangerous_shred Use GNU shred
- File names ending in a newline aren’t supported;
zaprefuses to trash (or restore) them.
macOS doesn’t record where trashed files came from in a form other tools can read, so when zap trashes something with one of the macos_* strategies, it writes its own record (a .trashinfo file with extra X-Zap-* keys) to $XDG_DATA_HOME/zap/info (default ~/.local/share/zap/info). zap --list and zap --restore use these records, so they only know about files that zap itself trashed.
Based on gtrash’s comparison table.
| AjaiKN/zap.sh | gtrash | trash-cli | trashy | trash-d | sindresorhus/trash-cli | ali-rantakari/trash | nateshmbhat/rm-trash | bashtrash | gomi | |
| Supports Linux? | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ (“not very good and not maintained”) | ❌ | ✅ (but doesn’t use $XDG_DATA_HOME env var) | ✅ | ✅ |
| Supports macOS system trash can? | ✅ | ❌ | ❌ | ❌ | ❌ | ✅ | ✅ | ❌ | ❌ | ❌ (previously supported?) |
| Supports Windows? | ❌ | ❌ | ❌ | ✅ | ❌ | ✅ | ❌ | ❌ | ❌ | ✅ |
| Language | Bash | Go | Python | Rust | D | JavaScript (+ Swift binary on Mac) | Objective-C | Bash | Bash | Go |
| Architecture | Single script | Single binary & Multi subcommands | Multi commands | Single binary & Multi subcommands | Single binary | Single command | Single binary | Single script | Single script | Single binary |
| Has rm-like interface | ✅ | ✅ | ✅ | ❌ | ✅ | ✅ (ignores all flags) | ✅ (ignores all flags) | ✅ | ✅ | ✅ |
| Command to put FILE in trash | zap FILE | gtrash put FILE | trash-put FILE | trashy FILE or trashy put FILE | trash FILE | trash FILE | trash FILE | rm-trash FILE | trash FILE | gomi FILE |
| Command to list trash contents | zap --list | gtrash find | trash-list | trashy list | trash --list | ❌ | trash -l | ❌ | ❌ | ❌ |
| Command to restore FILE from trash | zap --restore FILE | gtrash find REGEX --restore | trash-restore | trashy restore REGEX | trash --restore FILE ️ | ❌ | ❌ | ❌ | ❌ | gomi --restore |
| Command to permanently delete/empty FILE from trash | ❌ | gtrash find REGEX --rm | trash-rm FILE | trashy empty FILE | trash --delete FILE | ❌ | ❌ | ❌ | ❌ | ❌ |
| Command to fully empty trash | ❌ | gtrash find --rm | trash-empty | trashy empty --all | trash --empty | available in separate project | trash -e (or securely with trash -s) | ❌ | ❌ | gomi --prune=0m |
| Restore with TUI | ❌ | gtrash restore | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | gomi --restore |
| Restore as a group | ❌ | ✅ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ |
| Can show file and directory size | ❌ | ✅ | ❌ | ❌ | ❌ | N/A | ❌ | N/A | N/A | ❌ |
| Can show summary of trash cans (total items, size) | ❌ | ✅ | ❌ | ❌ | ❌ | N/A | ❌ | N/A | N/A | ❌ |
| Support FreeDesktop.org directorysize cache | ❌ | ✅ | ❌ | ❌ | ✅ (only put, cannot list) | ❌ | N/A | ❌ | ❌ | ❌ |
| Support FreeDesktop.org external filesystem trash can | ✅ | ✅ | ✅ | ✅ | ❌ | ✅ | N/A | ❌ | ✅ | ✅ |
| Support FreeDesktop.org fallback to home trash | ✅ | ✅ | ✅ | ❌ | N/A | N/A | N/A | |||
| Multiple strategies | ✅ (many) | ❌ | ❌ | ❌ | ❌ | ❌ | ✅ (Finder/AppleScript or system API) | ❌ | ❌ | ✅ (XDG or “legacy”) |
| Size-based pruning | ❌ | ✅ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ |
| Date-based pruning | ❌ | ✅ | trash-empty DAYS | ✅ | ❌ | ❌ | ❌ | ❌ | ❌ | ✅ |
| Safe (show confirmation prompt before deleting by default) | N/A | ✅ | ❌ | ✅ | ❌ | ❌ | ✅ | N/A | N/A | ✅ |
| Sort trashed items by deletion date by default? | ✅ | ✅ | ❌ | ✅ | ❌ | N/A | ❌ | N/A | N/A | ✅ (when pruning) |