Skip to content
/ trsh Public

Ever accidentally deleted the wrong file using rm or even worse rm -R ? With trsh, you can delete with confidence knowing you can always restore. Unlike rm, trsh gives you a safety net.

License

Notifications You must be signed in to change notification settings

elias-ba/trsh

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

17 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿ—‘๏ธ trsh

License: MIT Python 3.7+

Delete with Confidence, Restore with Ease

A trash utility that makes file deletion safe, recoverable, and intelligent.

Ever accidentally deleted the wrong file? With trsh, you can delete with confidence knowing you can always restore. Unlike rm, trsh gives you a safety net.

โœจ Features

  • ๐Ÿ—‘๏ธ Safe Delete - Move files to trash instead of permanent deletion
  • โ™ป๏ธ Easy Restore - Restore deleted files with pattern matching or interactive mode
  • ๐Ÿ” Powerful Search - Find files by name, path, date, size, or tags
  • ๐Ÿ“Š Rich Analytics - View statistics and deletion patterns
  • ๐Ÿท๏ธ Tag System - Organize deleted files with custom tags
  • โฎ๏ธ Undo Support - Undo accidental deletions instantly
  • ๐Ÿ”’ Safety Checks - Prevents deletion of critical system paths
  • ๐Ÿ’พ Deduplication - Saves space by detecting duplicate files
  • ๐ŸŽจ Beautiful Output - Colored, formatted terminal output
  • ๐Ÿš€ Fast - SQLite-backed for quick queries
  • ๐Ÿ“ฆ Zero Dependencies - Uses only Python standard library

๐Ÿš€ Installation

Quick Install

# Download and install
curl -o trsh.py https://raw.githubusercontent.com/yourusername/trsh/main/trsh.py
chmod +x trsh.py
sudo mv trsh.py /usr/local/bin/trsh

# Or for user install
mkdir -p ~/.local/bin
mv trsh.py ~/.local/bin/trsh
export PATH="$HOME/.local/bin:$PATH"

From Source

git clone https://github.com/yourusername/trsh
cd trsh
pip install -e .

Requirements

  • Python 3.7+ (only standard library needed!)
  • No external dependencies required! ๐ŸŽ‰

๐Ÿ“– Usage

Basic Commands

# Delete files
trsh delete file.txt
trsh delete *.log --tags temp

# Restore files
trsh restore document.pdf
trsh restore "*.txt"

# List trash
trsh list
trsh list --last 7
trsh list --verbose

# Search
trsh search "report"
trsh search "invoice" --from ~/documents --size ">1MB"

# Empty trash
trsh empty

# View statistics
trsh stats

# Undo last operation
trsh undo

Advanced Usage

# Delete with metadata
trsh delete old_files/ --reason "cleanup" --tags project-x deprecated

# Restore to different location
trsh restore backup.tar.gz --output ~/Desktop/

# Search with multiple filters
trsh search "2024" --from ~/documents --size "<1GB" --last 90d --tag important

# Purge old files
trsh purge --older-than 30
trsh purge --size-quota 10  # Keep only 10GB

# Preview before executing
trsh delete *.tmp --dry-run
trsh empty --dry-run

# View operation history
trsh history
trsh history --limit 50

# Verify trash integrity
trsh verify
trsh verify --repair

# Configuration
trsh config set retention-days 30
trsh config list

๐ŸŽจ Example Session

$ trsh delete ~/Downloads/*.zip --tags downloads
โœ“ Deleted: /home/user/Downloads/archive1.zip (45.2 MB)
โœ“ Deleted: /home/user/Downloads/archive2.zip (32.1 MB)

$ trsh list
2025-10-01 14:32    45.2 MB  /home/user/Downloads/archive1.zip  [downloads]
2025-10-01 14:32    32.1 MB  /home/user/Downloads/archive2.zip  [downloads]

โ„น 2 items, 77.3 MB total

$ trsh stats
๐Ÿ“Š Trash Statistics
โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
Items in trash: 2
Total space used: 77.3 MB
Items restored (all time): 0
Restoration rate: 0.0%

$ trsh restore archive1.zip
โœ“ Restored: /home/user/Downloads/archive1.zip

$ trsh undo
โœ“ Undone: Restored 1 files

๐Ÿ—๏ธ Architecture

Storage Structure

~/.trashbin/
โ”œโ”€โ”€ files/                    # Actual trashed files
โ”‚   โ”œโ”€โ”€ uuid-1/
โ”‚   โ”‚   โ””โ”€โ”€ document.pdf
โ”‚   โ””โ”€โ”€ uuid-2/
โ”‚       โ””โ”€โ”€ image.png
โ””โ”€โ”€ metadata.db              # SQLite database

Database Schema

  • trash_items: File metadata, paths, hashes, tags
  • operations: Transaction log for undo/redo
  • config: User preferences

๐Ÿ”ง Shell Integration

Add to your ~/.bashrc or ~/.zshrc:

# Replace rm with trsh (safely!)
alias rm='trsh delete'

# Quick access
alias trash='trsh list'
alias restore='trsh restore'
alias undelete='trsh undo'

Then reload:

source ~/.bashrc  # or source ~/.zshrc

Now rm is safe:

rm file.txt      # Actually uses trsh!
trash            # See what's in trash
restore file.txt # Get it back

๐Ÿ“Š Comparison

Feature trsh trash-cli gio trash rm
Cross-platform โœ… โœ… Linux only โœ…
Database SQLite Custom GIO None
Deduplication โœ… โŒ โŒ โŒ
Advanced search โœ… Basic Basic โŒ
Interactive restore โœ… โŒ โŒ โŒ
Undo โœ… โŒ โŒ โŒ
Tags โœ… โŒ โŒ โŒ
Analytics โœ… โŒ โŒ โŒ
Dependencies None Python GLib None

๐Ÿค Contributing

Contributions are welcome! Please read CONTRIBUTING.md first.

Development Setup

git clone https://github.com/yourusername/trsh
cd trsh
conda create -n trsh python=3.11 -y
conda activate trsh
conda install -y pytest pytest-cov black pylint mypy
python test_trsh.py

Running Tests

python test_trsh.py
pytest test_trsh.py -v
pytest --cov=trsh test_trsh.py

๐Ÿ“ License

MIT License - see LICENSE file for details.

๐Ÿ‘ค Author

Elias W. BA

๐Ÿ™ Acknowledgments

  • Inspired by trash-cli, macOS Trash, and Windows Recycle Bin
  • Built with Python's excellent standard library

โญ Support

If you find this tool useful:

  • โญ Star the repository
  • ๐Ÿ› Report bugs
  • ๐Ÿ’ก Suggest features
  • ๐Ÿค Contribute code

Made with โค๏ธ and Python

"The best time to delete a file was yesterday. The second best time is now... with trsh!"

About

Ever accidentally deleted the wrong file using rm or even worse rm -R ? With trsh, you can delete with confidence knowing you can always restore. Unlike rm, trsh gives you a safety net.

Resources

License

Contributing

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published