0

To delete directories you need to use the command rmdir instead of rm. I learned that unix sees everything as a file. So what is the reason that rm can't delete any type of file?

Natjo
  • 845

1 Answers1

2

Why you shouldn't remove a directory 'as if it were a file' if it's not empty seems rather obvious: then the files in that directory would not have a valid path anymore. This explains why you need either to delete recursively (-r) or check that the directory is empty before deleting (rmdir, or, in some branches of Unix, rm -d).

According to Wikipedia, citing Unix 8 rm man page, in some old versions of Unix, the rm command would delete directories if they were empty, so this is more a choice of user interaction of some Unix versions than a requirement.

Joce
  • 1,092