rm -r versus rm -d?

I see a lot of resources on rm -r but almost nothing on rm -d even though the d flag is apparently all about deleting directories.

What is the difference between the two exactly? Is rm -d the same as rmdir? Is it "safer" than rm -r?


I tried both commands and here are my conclusions:

  • rm -d works just like rmdir (unless there's something going on with links or something like that).
  • rm -r deletes the target directory and recursively deletes everything inside that directory (including non-empty directories and files of any type)

So the difference is pretty clear. There's no doubt that rm -r is a really dangerous command that should be used very carefuly (Example: rm -rf / can potentialy delete your system; or rm -rf * could delete your current project), while rm -d will only let you delete empty directories

Warning

Remember that rm -rd is a valid command and it will work like rm -r, so be careful.


A difference between rm -rd and rm -rf is that the former will prompt you before deleting a write-protected file or directory, while the latter will go ahead and delete write-protected files without prompting if it can do so. While rm -rd and rm -rf are both recursive and potentially dangerous if directed to the wrong directory, the former provides a little more protection against doing something you really didn't want to do.