rmdir stands for remove directory.
In the UNIX file system, we can remove directory by using rmdir command.
$ rmdir [directory name]
Note: In above syntax in the place of [directory name] we will specify the name of the directory to be removed.
$ rmdir abc [press enter]
The directory abc is removed. To confirm directory is created press “ls” command which prints the name of all files and directory.
Remove multiple directories: We can remove multiple directories with the single invocation of the command. Suppose we want to remove three directory abc1, abc2 and abc3 then the command for removing three directories shown in below.
$ rmdir abc1 abc2 abc3 [press enter]
Remove subdirectory: We can remove directory inside another directory by using a single invocation of the command.
Suppose we want to remove directory abc and subdirectory abc1 and abc2 inside the directory abc then the command is as follows.
$ rmdir abc/abc2 abc/abc2 abc [press enter]
Above command remove directory abc and subdirectory abc1 and abc2.
Note: The order of specifying argument important because we can not remove directory without removing its subdirectory. For example, we can not write
$ rmdir abc abc/abc2 abc/abc2 [press enter]
rmdir: failed to remove directory ”abc”; Directory not empty.
Command rmdir failed to remove directory abc because abc is not empty but it will remove two subdirectory abc1 and abc2.