rm safely.
rm-safely is a safety shell alias to prevent the accidental deletion of important files, especially, default MacOS rm
This is just a handy shell wrapping function along with option to directly invoke /bin/rm with --rm.
If you always use /bin/rm -i or alias it already, you will probably be fine.
But, with this rm-safely alias, it should prevent you in case of autocomplete from shell history that left of with unintended rm -rf.
Keys,
- Written in shell script, no dependencies.
- Save files in
~/.local/share/Trashand in/.Trash-$(id-u)for mounted volumes. - Tested on:
- Shell
- zsh
- OS:
- macOS 15.5+
- Linux arch-linux 6.17.1-2-cachyos
- Shell
Via curl:
curl -fsSL https://raw.githubusercontent.com/zdk/rm-safely/main/rm-safely | bash -s install
Via homebrew:
brew install zdk/tools/rm-safelyUse rm command to delete things as usual, but safer \(◎o◎)/
In other words when you run rm -rf file directory/
You will have files/dir the trash first, then you can decide to delete or clean them later on.
rm -rm Skip trash!, really execute 'rm'
rm -list-trash, -l Show trash contents from all filesystems
rm -restore <hash>, -s Restore a file from trash using its hash
rm -undo, -u Restore the last deleted files
rm -empty-trash Empty all trash directories
rm -show-trash-path, -p Display all trash directory paths
rm -version Show version information
rm -help Show this help
If you don't really care to move it to Trash first.
rm-safely provide bypass to your OS rm via --rm option.
That means, use rm --rm
For examples:
- remove files and directy with OS rm.
rm --rm file directory/
- see the OS rm --help
rm --rm --help
/bin/rm: illegal option -- -
usage: rm [-f | -i] [-dIPRrvWx] file ...
unlink [--] file
--rm is nothing special other than execute /bin/rm from current shell.
Or, you could just /bin/rm directly.
curl -fsSL https://raw.githubusercontent.com/zdk/rm-safely/main/rm-safely | bash -s uninstall
-
Main goal of rm-safely is to write it in a pure shell script as a gateway and a suppliment to rm, not a replacement.
-
Alternative tools:
[Important Reminder],
Regarding the normal bahaviour of unix alias,
- Please keep in mind, the rm-safely alias is available in current user only.
And, you have a few options to make the alias available in another user like so:
-
Make sure you install in each user you need to have alias available. (Either manually or dotfiles should work)
-
Always use
sudo -sto switch to root or another, then runrmin the next step as a good habit anyway.