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
  • 1
    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
  • 2
    For those who are wondering, the '--preserve-root' was made the default for rm in core-utils on 2016-09-02 in: git.savannah.gnu.org/gitweb/…
    – qneill
    Mar 28 '18 at 19:01

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:

          do not treat '/' specially

          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.