0

A question I already asked myself a few times is why I can't delete the current working directory using rm -r .

The shell does not have a problem with a non-existing directory as working directory, so I just created an alias for rm -r "../$(basename "$(pwd)")".

Why is there a difference between these two rms, while the output of realpath . and realpath "../$(basename "$(pwd)")" does not differ and the cwd of the rm is also the same?

krissi
  • 553

1 Answers1

3

As explained in Does 'rm .*' ever delete the parent directory? the following part of the POSIX spec applies:

If either of the files dot or dot-dot are specified as the basename portion of an operand (that is, the final pathname component) or if an operand resolves to the root directory, rm shall write a diagnostic message to standard error and do nothing more with such operands.

krissi
  • 553