How can I make "rm -rf / " into an alias?
I want to make an alias for rm -rf /. I know how to make an alias; the problem is that I don't know how to use a succession of commands to make an alias with all of them. I want something like rm -rf / = echo 'something', but only when "/" is used.
How can I achieve this?
163 Answers
This would be much better done by applying the appropriate permissions to prevent people from deleting stuff.
This aliasing ‘security’ approach would be easily overridden by disabling the alias, symlinking to rm and running it that way, copying the rm binary, or possibly even running it directly.
You should secure your desktop by pressing Ctrl+Alt+L to lock it when leaving it unattended.
4A simple bash function would do (but this can obviously be overwritten by an user):
rm () { [[ $1 =~ -(rf|fr) && $2 = / ]] && echo "whatever" || command rm "$@" ;}Note that, even if some user do rm -rf /, the operation would not go on as one needs to input --no-preserve-root option with rm to remove the root directory recursively. (But nothing is preventing one from doing rm -rf /* or cd /; rm -rf * by the way)
But you should look at implementing a good security policy instead of monkey-patching sensitive stuffs.
10The real problem here is your system's security. The "ppl" that you work with shouldn't be able to rm -rf / since that requires root access - implementing a better security model would avoid incompetent people from breaking the system, plus your rm command should (if it's a recent version) implement --no-preserve-root.