trs (from TRaSh) — a secure CLI utility for moving files to trash using the XDG Trash specification.
- Safe by default - Files go to trash, not /dev/null
- XDG compliant - Works with GNOME, KDE, and other desktop environments
- Security-focused - Protected against symlink attacks, path traversal, and DoS
- No dependencies - Pure Go, no external utilities needed
- Cross-device - Handles files on different filesystems automatically
# apt-get install trsgo install altlinux.space/amakeenk/trs@latesttrs file.txt # Move a file to trash
trs file1.txt file2.txt # Move multiple files
trs -r directory/ # Move a directory (recursive)
trs -f nonexistent # Force (ignore nonexistent files)
trs -v file.txt # Verbose outputtrs list # List all trashed files
trs list --json # JSON outputOutput:
# NAME SIZE DELETED ORIGINAL PATH
1 config.json 1.2KB 2026-03-05 10:30 /home/user/project/config.json
2 old_backup/ 45MB 2026-03-04 18:22 /home/user/backups/old_backup
trs manage # Interactive TUI with fuzzy search
trs manage config.json # Restore by name
trs manage 1 # Restore by index (from list)
trs manage --last # Restore most recently trashed file
trs manage -f file.txt # Force overwrite existing file
trs manage --json # JSON outputTUI features:
- Multi-select with Tab/Space, arrow navigation
- Select all with
aorCtrl+a, deselect all withA - Fuzzy search across names and original paths
- Press
rto restore ordto permanently delete selected files - Results show full original paths
trs empty # Empty entire trash
trs empty --days 7 # Only files older than 7 days
trs empty --json # JSON outputtrs status # Show trash statistics
trs status -v # Verbose (oldest/newest/largest files)
trs status --json # JSON outputOutput:
Trash: 42 files, 128.5 MB
With -v:
Trash: 42 files, 128.5 MB
Oldest: 2026-02-01 10:00 Newest: 2026-03-10 15:30
Largest: backup.tar (50MB), video.mp4 (25MB), data.zip (10MB)
trs version
trs version --jsontrs completion bash # Bash
trs completion zsh # Zsh
trs completion fish # Fish
trs completion powershell # PowerShell- Home trash:
~/.local/share/Trash/ - Volume trash:
$VOLUME/.Trash-$UID/ - Cross-device moves handled automatically
- Compatible with desktop environment trash
The trs manage command launches an interactive terminal UI:
- Fuzzy search across file names and original paths
- Arrow key navigation with live preview
- Multi-select files with Tab/Space
- Select all with
aorCtrl+a, deselect all withA - Press
rto restore ordto permanently delete selected files - Confirmation screen before action
- Works in any terminal
trs implements multiple security measures:
- Symlink protection - Never follows symlinks when copying or removing
- Path validation - Prevents path traversal attacks
- TrashInfo validation - Validates paths from
.trashinfofiles - DoS prevention - Size and iteration limits on all operations
- Directory validation - Verifies trash directory ownership and permissions (protected against TOCTOU)
- Safe removal - Uses
os.RemoveAllwhich is safe against symlink attacks on modern Unix systems
All commands support --json for scripting:
trs list --json | jq '.[] | .name'
trs status --json | jq '.totalSize'XDG_DATA_HOME- Custom data directory (default:~/.local/share)NO_COLOR- Disable colored output
0- Success1- Error2- Invalid usage
| Feature | rm |
trs |
|---|---|---|
| Permanent deletion | Yes | No |
| Trash can | No | Yes |
| Undo/restore | No | Yes |
| Safe by default | No | Yes |
| XDG compliant | No | Yes |
make build # Build binary
make test # Run tests
make coverage # Test coverage
make coverage-html # Coverage HTML report
make install # Install to $GOPATH/bingo test ./... -v
go test -run TestManager_Move ./internal/trash/...MIT License - see LICENSE for details.
- Fork the repository
- Create a feature branch
- Make your changes
- Run tests:
make test - Submit a pull request
See CHANGELOG.md for version history.
This project was entirely implemented with AI assistance.