7

They say rm command defaults to the option --preserve-root. Is that right?

Otherwise I should put the line

alias rm='rm --preserve-root'`

in ~/.bashrc to make that option happen without typing it every time I run the rm command. To confirm this I ran type rm, and got rm is hashed (/bin/rm).

I expected rm is aliased to rm --preserve-root. Does anyone know what's going on with the rm command?

  • 1
    sorry I have no idea who "they" are, but I think you'll find it depends on your kernel & shell/bash version. I know some of the systems I use (which are still supported) don't have --preserve-root on rm. – guiverc Dec 1 '17 at 12:34
  • Oh, I said they cause I'm reading a book, whose name is like Ubuntu Unlished 2017 or something. I thought saying specific book name makes me look like book seller, so I did like that. My ubuntu version is Ubuntu 16.04. I still want to know how to confirm whether --preserve-root is default or not. – Smile Dec 1 '17 at 12:42
  • At least for me I get for sudo rm -r / the following message: rm: it is dangerous to operate recursively on '/' and rm: use --flag-i-wont-mention to override this failsafe – Videonauth Dec 1 '17 at 12:44
  • 1
    This is also present in the manpage for rm. – user595510 Dec 1 '17 at 12:57
  • 1
    @guiverc It has nothing to do with the kernel, or your shell (bash or otherwise). It's a default option in GNU rm since some years, which is a separate program from your shell. (It's in coreutils in Debian and Ubuntu). – marcelm Dec 1 '17 at 13:46
8

rm is not being aliased to rm --preserve-root, but the option is selected by default in the rm binary.

From the manpage of rm in Ubuntu 17.10, you can find the following details of the --preserve-root and --no-preserve-root options:

   --no-preserve-root
          do not treat '/' specially

   --preserve-root
          do not remove '/' (default)
  • I have read man page, but I totally missed the "(default)". Thanks for the reply. BTW when you mention 'rm binary', did you mean rm is programmed in that way?? – Smile Dec 1 '17 at 12:56
  • @Smile Yes, that's what it means. – user595510 Dec 1 '17 at 12:57

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.