A safe replacement for rm that moves files to a local trash instead of deleting them permanently.
Built with modern C++17 using only standard libraries.
Safe‑Delete keeps things simple on purpose. When you “delete” a file, it doesn’t destroy it. It moves a verified copy into a private trash folder under your home directory:
~/.safe-trash/<unique-id>/
Inside that folder you’ll see:
- the original file or directory (same name as before)
- a small
meta.txtfile with info like original path, time, size, and permissions
safe-rm: copies the file/dir into~/.safe-trash, checks the copy exists, then removes the originalsafe-list: reads allmeta.txtfiles and prints a simple tablesafe-restore: moves an item back to its original path (asks you if there’s more than one match)safe-purge: deletes old entries (or everything if you confirm)
It’s boring on purpose: no cloud, no GUI, no system Trash tricks. Everything is just files and folders you can inspect. That makes it easy to trust, easy to debug, and easy to extend later.
This project is intentionally simple today, but it provides unique, out‑of‑the‑box additions that almost none operating system offers by default. Its originality is in being a local‑first, developer‑friendly safety layer that you can inspect and control — no system Trash quirks, no cloud, no magic.
From the project root:
git clone https://github.com/PavloICSA/safe-delete.git
cd safe-delete
cmake -B build
cmake --build buildRight now you can run the binary with a full path, like:
/path/to/safe-delete/safe-rm file.txtThat works from any folder. To make it even smoother, choose one of these options:
Add this line to your ~/.zshrc:
export PATH="/path/to/safe-delete:$PATH"Then reload your shell:
source ~/.zshrcNow you can run:
safe-rm file.txtfrom anywhere.
If you want protection by default, add this after the PATH line:
alias rm='safe-rm'Now any rm you type in your Terminal will use Safe-Delete instead.
Open a new Terminal window and run:
which safe-rmIf it prints the path to your project, you're all set.