Frequently Asked Question
How do mkdir and rmdir differ from rm -r?
mkdir creates a directory; mkdir -p a/b/c/d creates any missing parents along
the way so the command does not fail if a/b does not yet exist. rmdir is the
strict counterpart: it removes a directory but only if it is completely empty.
That deliberate timidity makes it safe to use in scripts where you only want to
tidy up if there is nothing left to lose; if the directory still contains files,
rmdir refuses and exits with a non-zero status.
rm -r is the unsafe-but-useful equivalent. It walks the directory recursively,
deleting everything it finds, and then removes the directory itself. There is no
check for emptiness, no confirmation by default, and no Recycle Bin. rm -rf adds
"force", silence all errors and never prompt. Together they are the most dangerous
pair of letters on the system. A common pattern is to write rm -rI (capital I)
for interactive scripts, which asks once before deleting more than three files.