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?

  • 9
    it sounds like you want to make a (probably ill-advised!) function...
    – Zanna
    Nov 23, 2016 at 12:06
  • 8
    @CaranfilAlegzandru It seems to me that you missinterpreted the concept of an alias. An alias is an alternative name for a command. It doesn't disable or replace the original command. If I, for example, added the alias ll for ls -l, both ll and ls -l would have the same effect. Nov 23, 2016 at 12:30
  • 5
    @CaranfilAlegzandru An alias just isn't a suitable tool in your case. You don't want to add another way of doing rm -rf, you want to disable or superseed the original one. And that's not what an alias does, it adds another name to a command. heemayl's answer is a more feasible approach. Nov 23, 2016 at 13:13
  • 2
    I agree that an alias isn't a suitable tool for the OP's goal, but, @HenningKockerbeck, you're harping on an overly narrow interpretation of a technicality. If I alias ls=date then, yes, I have defined a new way to learn (and, possibly, set) the system date and time — but I've also disabled the ls command from listing files. (And, yes, I know that it's trivial to circumvent, but that's not the point.) Nov 23, 2016 at 17:10
  • 1
    @CaranfilAlegzandru You don't need to do anything; rm already does this by itself. # rm -rf / says rm: it is dangerous to operate recursively on ‘/’ - rm: use --no-preserve-root to override this failsafe.
    – marcelm
    Nov 23, 2016 at 21:44

3 Answers 3


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.

  • also scripts that run 'rm' might be confused by the extra output of your alias
    – Amias
    Nov 23, 2016 at 12:54
  • 1
    But that would be an issue only if the user runs a script that runs rm -rf / (which seems unlikely), and then only if the shell that's running the script expands aliases (which is not default behavior). Nov 23, 2016 at 17:25
  • 1
    +1 Security through obscurity is generally a bad idea.
    – jpmc26
    Nov 23, 2016 at 20:26
  • Adding to this answer, this is precisely why Linux allows multiple logins. Create separate logins for your "ppl" -- don't make them administrators! -- or simply enable guest login and let them login as guests. If you do either of these, they can mess themselves up all they like, but they cannot mess up the system or your account. Nov 28, 2016 at 23:16

A 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.

  • They have 0 experience with linux. They are monkeys, they see a picture on google with "sudo rm -rf / - bla bla" they did it. I wanted just something that can confuse them. and this seems to be a good idea. Thank you ! Nov 23, 2016 at 12:27
  • 1
    Monkey see, monkey do ;) Nov 23, 2016 at 12:49
  • @WinEunuuchs2Unix exactly! There are some problems where i work and tbh i don't have time to reinstall the os every time a monkey wants to try that again. And a lot of time i forget to lock my laptop when i go for a smoke or whatever. my fear is that these guys will try it again, only next time they will do it on a production server. Nov 23, 2016 at 12:54
  • 1
    Sounds like a great laptop webcam app to lock the screen when no motion for 1 minute (is you are away from your desk but not just at your filing cabinet in the corner for a minute) Nov 23, 2016 at 13:03
  • 3
    also , give up smoking ;)
    – Amias
    Nov 23, 2016 at 15:18

The 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.

  • 2
    As long as the machine is unlocked, anybody can type rm -rf /. They shouldn't be able to delete the entire filesystem if they don't have root access, but, if it doesn't bail immediately (because --no-preserve-root wasn't specified), rm -rf / will traverse the directory tree recursively until it reaches the OP's home directory and other files that he is able to delete. Nov 23, 2016 at 17:58
  • This. Root should be required to rm -rf / and gaining root should require a password. Problem solved. If either root can be gained without password or root is not required, your security is insufficient.
    – Mast
    Nov 23, 2016 at 22:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.