2

We all know that we have to use the -rf option of rm command carefully. What I wonder is does Linux allow executing this command: rm -rf /?

If so, why? This command could have disastrous consequences if allowed to run:

  1. It would delete everything including files on the hard drive and files on connected removable media devices.
  2. How can we remedy the situation, especially without the assistance of all the executable commands which would also be deleted?

1 Answer 1

11

You cannot run rm -rf /: you'll get the error “permission denied”. Only root can modify the root directory.

If you run this command as root (e.g. with sudo rm -rf /), Linux actually refuses to run it. You need to pass a special option --no-preserve-root in order to call rm on /.

You can still run dangerous commands, e.g. rm -rf ~ will delete all your files. It's like having a kitchen knife: it's very handy to cut all kinds of food, but if you point it towards your neck and push hard, you will get hurt.

Fortunately, recovering from rm -rf ~ is easier than recovering from inserting a knife into your neck. You do have backups, right?

1
  • "....than recovering from inserting a knife into your neck" that is a great line!! Commented Oct 11, 2018 at 15:49

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.