Best practices to alias the rm command and make it safer
If you want a customized rm
, don't call it rm
but a name of yours, myrm
, delete
or whatever.
The rm='rm -i'
alias is an horror because after a while using it, you will expect rm
to prompt you by default before removing files. Of course, one day you'll run it with an account that hasn't that alias set and before you understand what's going on, it is too late.
In any case, a good way to be prepared for file loss or corruption is doing backups.
A fast alternative that will protect you against accidental file deletion or overwriting is using a file system that support unlimited snapshots like ZFS. If frequent snapshots are done automatically, you can recover the files at the state they were during the last snapshot before the incident.
If you want save aliases, but don't want to risk getting used to the commands working differently on your system than on others, you can to disable rm
like this
alias rm='echo "rm is disabled, use remove or trash or /bin/rm instead."'
Then you can create your own safe alias, e.g.
alias remove='/bin/rm -irv'
or use trash
instead.
You could try using trash
instead. Just remember to empty it once in a while...