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?

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

1 Answer 1

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.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.