I think it's quite simple.

If `rmdir TESTD` succeeds, then the two links which refer to it, `TESTD/.` and `TESTD` are removed.  So the link count of the specified directory is reduced by 2.  This can be verified by running a shell inside the directory and running `ls -ld` after the directory has been unlinked (removed from its parent).

Once a file (such as a directory) has 0 links, and no running processes with a reference (file descriptor or current directory), it will be truly deleted.

You can try to observe true deletion by looking at the used disk blocks in `df .`.  It works in Linux `ext4` filesystems.  Other filesystems may have more complex optimizations though, making it harder to observe.


`rmdir` fails if "pathname contains entries other than . and .." (`man 2 rmdir`).  After `rmdir` succeeds, the directory will be completely empty.  This guarantees that there are no sub-directories, so they won't have any `..` links, to keep the directory's link count above 0.