resrm
resrm is a safe, drop-in replacement for the Linux rm command with undo/restore support.
It moves files to a per-user trash instead of permanently deleting them, while still allowing full sudo support for root-owned files.
Features
- Move files and directories to a Trash folder instead of permanent deletion
- Restore deleted files by short ID or exact basename
- Empty trash safely
- Supports
-r,-f,-i,--skip-trashoptions - Works with
sudofor root-owned files - Automatically prunes Trash entries older than
$RESRM_TRASH_LIFEdays (default 7, minimum 1)Note: if you need immediate deletion, use the regular
rmcommand instead.
Configuration
To control how long trashed files are kept, add this line to your shell configuration (e.g. ~/.bashrc):
export RESRM_TRASH_LIFE=10
Installation
NOTE: To use resrm with sudo, the path to resrm must be in the $PATH seen by root.
Either:
- install
resrmasroot(preferred), or - add the path to
resrmto thesecure_pathparameter in/etc/sudoers. For example, where/home/user/.local/binis whereresrmis:
Defaults secure_path="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/home/user/.local/bin"
Install via PyPI (preferred):
pip install resrm
Or clone the repo and install locally:
git clone https://github.com/mdaleo404/resrm.git
cd resrm/
poetry install
Usage
# Move files to trash
resrm file1 file2
# Recursive remove of a directory
resrm -r mydir
# Force remove (ignore nonexistent)
resrm -f file
# Interactive remove
resrm -i file
# Permanent delete (bypass trash)
resrm --skip-trash file
# List trash entries
resrm -l
# Restore a file by ID or basename
resrm --restore <id|name>
# Empty the trash permanently
resrm --empty
Trash Location
Normal users: ~/.local/share/resrm/files
Root user: /root/.local/share/resrm/files
Description