The rm -r command is used to remove directories and everything inside them. First, it checks if the target directory exists. If it does, it checks if it is a directory. If yes, it removes all files and subdirectories inside recursively. After all contents are deleted, it removes the directory itself. If the target is a file, it deletes it directly. This process ensures directories are empty before deletion. The execution table shows each step: checking existence, removing files, removing subdirectories, and finally removing the main directory. Beginners often wonder why files are removed first; this is because directories cannot be deleted unless empty. Also, if the directory is empty, the recursive steps are skipped and the directory is deleted immediately. Always be careful with rm -r because it deletes permanently without confirmation.