Introduction (you can skip it)
rm -i would be enough, because it prompts you before deleting any file. However, some extra security provided by
safe-rm isn't a bad idea at all.
rm=safe-rm -i could be enough, however
rm -rf would not work, because
-i is overriden by
So, we have to make sure that
-i always come after
My solution (3 steps):
brew install safe-rm
You can still work with
rm, but you have modify the
RM_BIN in the next step
~/.profile (or bash_profile or whatever), and put the following code snippet, (which contain an
alias and a
RM_BIN=safe-rm # you can replace it with regular rm if you like
argsDone=0 # to make sure arguments are before the files
for var in "$@"
if [[ $var == \-* ]] ; then
if [ $argsDone -eq 1 ] ; then
$RM_BIN # just to show the usage of rm
args+=" -i" # Put -i at the end (so rm -rf will not ignore it)
$RM_BIN $args $files
login, so the updates in the .profile are applied. DON'T use it before a logout/login!
- It can be applied to any Linux distro, with slight modifications.
- It does NOT move your staff to thrash. It just asks you before deleting each file!
- It works with
-rf and with regexes.
- If you really want to use
rm -rf WITHOUT being asked for every single file/folder you can still use
/bin/rm -rf (or
safe-rm -rf if you had installed it).
- No more unintentional
rm -rf or
rm * ;)