Account
Categories

rmdir command


Definition:

This command removes only empty directories. You can remove multiple directories at once. It can also remove one or more directories located inside other directories at a different location if you provide their full path.


Syntax:

rmdir [option] directory_name
    

Option:

-p -> Use this option when you want to delete multiple directories at once.
    

Example 1:

Command:
rmdir myfolder
    

Output:

The folder myfolder is deleted. No message appears in the terminal.
    

Example 2:

Command:
$ rmdir -p dir1/dir2/dir3
    

Output:

All folders dir3, dir2, dir1 are deleted if they are empty. 

If any folder is not empty, an error appears, for example:
rmdir: failed to remove 'dir2': Directory not empty