Do frequent backups, use snapshots (à la time machine) if your file system is ZFS
or btrfs
, train your fingers to use the right commands, but I would advise to avoid changing rm
behavior and semantics.
Doing it will sooner or later backfire, just like the obnoxious alias rm="rm -i"
...
What I would advise instead in your case would be, when running interactive shells, to have rm
disabled and being substituted by a custom rm
that will do its original job. e.g. append these lines to your .bashrc
rm() {
echo "rm disabled, use myRM instead"
}
alias myRM="command rm"
The annoyance created by the new rm
function will be more efficient to help you getting rid of the typing mistake and you likely quickly cease to type rm
.
While this advice looks counterproductive, the reason why I suggest doing it this way is there is no risk for you to be accustomed to a non standard still working behavior for such a dangerous Unix command. Sooner or later, you'll be logged under an account and/or another system without the hack in place and you'll remove files with no security prompt to save them.
On the other hand, if you get used to type myRM
to remove files, doing it on foreign systems will be harmless.
Finally, should you nevertheless want to overload the rm
command, here is a concise way to do it:
rm() {
echo command rm $([ ${#} -gt 1 ] && echo \-i) "$@"
}
if
was the key. I had a hard time trying to concoct that! – dotancohen Mar 14 '16 at 14:04function rm { if [ "$#" -gt 1 ]; then command rm -i "$@"; else command rm "$@"; fi; }
? – Wildcard Mar 15 '16 at 00:08