rmdir
is a command-line utility for deleting empty directories. It is useful when you want to delete a directory only if it is empty, without needing to check whether the directory is empty or not.
To delete a directory with rmdir
, type the command followed by the name of the directory you want to remove. For example, to delete a directory named dir1
you would type:
$ rmdir dir1
If the directory is not empty, you will get the following error:
rmdir: failed to remove 'dir1': No such file or directory
In this case, you will need to use the rm
command or manually remove the directory contents before you can delete it.