This question already has an answer here:

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?

marked as duplicate by cuonglm, Shadur, X Tian, don_crissti, Gilles shell Sep 28 '15 at 11:22

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • Not really a duplicate, but the answer is applicable here. Thanks for the link. But who downvotes here?! – krissi Sep 28 '15 at 9:25
  • 1
    I don't know, never downvote a duplicated question, just voting to close it. – cuonglm Sep 28 '15 at 9:33

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.

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