Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I would like to know how we can restrict rm -rf /on CentOS machines?

share|improve this question

closed as too broad by bahamat, Anthon, slm, Zelda, jasonwryan Jan 18 '14 at 8:21

There are either too many possible answers, or good answers would be too long for this format. Please add details to narrow the answer set or to isolate an issue that can be answered in a few paragraphs.If this question can be reworded to fit the rules in the help center, please edit the question.

By default it shouldn't do any harm on recent versions as long as you don't use --no-preserve-root. – Marco Jun 1 '13 at 20:27
If you're in doubt, set up a VM and have some fun with rm just to get a feeling about what works and what doesn't. – Marco Jun 1 '13 at 21:14
[See this similar question][1] about another command. [1]: unix.stackexchange.com/questions/77696/… – Hauke Laging Jun 1 '13 at 21:33
Create /usr/local/bin/rm which plays Jingle Bells instead of removing files. – tripleee Jun 2 '13 at 6:17
"Restrict" how? – Michael Kjörling Aug 15 '13 at 7:34

Check out Safe-rm, it's basically a wrapper around rm that skips by default important directories (/, /bin, etc):

$ rm -rf /usr
Skipping /usr
share|improve this answer
The danger to such an approach (regardless of the exact tool; even alias rm='rm -i comes with such a caveat) is that you run the risk of getting used to having such protections in place, and then don't realize until it's too late when you're working on a system that doesn't have them. Instead, consider the fact that with great power comes great responsibility. Being logged in as root should not be taken lightly, and even as an ordinary user, rm -rf ~ can do quite a bit of damage if you don't have current backups. Moral of the story: have backups! – Michael Kjörling Dec 16 '13 at 19:25

I think the best way to restrict directories is to use sudo. If you add an user to the sudoers file and they go rm -rf --no-preserve-root / then there isn't much you can do, but normal users (not in the sudoers file) won't be allowed to do that at all.

share|improve this answer

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