Skip to content

Instantly share code, notes, and snippets.

@alexknowshtml
Created July 19, 2026 23:45
Show Gist options
  • Select an option

  • Save alexknowshtml/54cce8414335e2f2a4e49f954b10e4ab to your computer and use it in GitHub Desktop.

Select an option

Save alexknowshtml/54cce8414335e2f2a4e49f954b10e4ab to your computer and use it in GitHub Desktop.
Replace rm with a recoverable trash bin using rip (rm-improved)

Replace rm with a recoverable trash bin using rip

rip (rm-improved) sends deleted files to a graveyard instead of permanently removing them. You get 14 days to restore anything before it's automatically cleaned up.

Install

cargo install rm-improved

No cargo? Install Rust first: https://rustup.rs

Shell setup

Add this to your ~/.zshrc (or ~/.bashrc):

export RIP_GRAVEYARD="$HOME/.local/share/rip-graveyard"

rip() {
  case "$1" in
    --restore) shift; command rip --graveyard "$RIP_GRAVEYARD" --unbury "$@"; return ;;
    --list)    command rip --graveyard "$RIP_GRAVEYARD" --seance; return ;;
    --nuke)    command rip --graveyard "$RIP_GRAVEYARD" --decompose; return ;;
  esac
  command rip --graveyard "$RIP_GRAVEYARD" "$@"
  local bytes
  bytes=$(du -sb "$RIP_GRAVEYARD" 2>/dev/null | awk '{print $1}')
  if [[ -n "$bytes" && "$bytes" -gt 1073741824 ]]; then
    echo "⚠️  Graveyard is $(du -sh "$RIP_GRAVEYARD" 2>/dev/null | cut -f1) — run 'rm --nuke' to clear it"
  fi
}

alias rm="rip"

Then reload your shell:

source ~/.zshrc

Auto-cleanup (14 days)

Create two files to set up a daily systemd timer that permanently removes graveyard files older than 14 days.

~/.config/systemd/user/rip-cleanup.service

[Unit]
Description=Clean rip graveyard files older than 14 days

[Service]
Type=oneshot
ExecStart=/bin/bash -c 'find ~/.local/share/rip-graveyard -mindepth 1 -mtime +14 -type f -delete 2>/dev/null; find ~/.local/share/rip-graveyard -mindepth 1 -empty -type d -delete 2>/dev/null'

~/.config/systemd/user/rip-cleanup.timer

[Unit]
Description=Daily rip graveyard cleanup

[Timer]
OnCalendar=daily
Persistent=true

[Install]
WantedBy=timers.target

Enable it:

systemctl --user daemon-reload
systemctl --user enable --now rip-cleanup.timer

Usage

rm file.txt           # sends to graveyard (recoverable)
rm --list             # list deleted files in current directory
rm --restore          # restore the last deleted file
rm --nuke             # permanently delete everything in graveyard

Files stay recoverable for 14 days, then the timer cleans them up automatically. If the graveyard exceeds 1GB, you'll see a warning after any deletion.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment