rmdir command tutorial in linux/unix with examples and use cases

linux rmdir command – remove empty directories

Linux rmdir command is used to remove directories. If the directory is empty, it is removed. If the rmdir directory is not empty, the error message “Directory not empty”. You need to use the linux rm command to delete a non-empty directory.


 mkdir [OPTION]... DIRECTORY...


  • –ignore-fail-on-non-empty
    ignore each failure that is solely because a directory is non-empty
  • -p, –parents
    remove DIRECTORY and its ancestors; e.g., ‘rmdir -p a/b/c’ is similar to ‘rmdir a/b/c a/b a’
  • -v, –verbose
    output a diagnostic for every directory processed

Examples & Use Cases

Remove empty parent and child directories

In the following example we will remove both the empty parent directory and the empty subdirectory at the same time.

 ➜  rmdir -p test-1/a

This entry was posted in Linux File & Directory and tagged , . Bookmark the permalink.