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.

Syntax

 mkdir [OPTION]... DIRECTORY...

Options

  • –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

Related post


Linux common commands tutorial and use examples
du command tutorial in linux/unix with examples and use cases
mkdir command tutorial in linux/unix with examples and use cases
touch command tutorial in linux/unix with examples and use cases
cd command tutorial in linux/unix with examples and use cases
pwd command tutorial in linux/unix with examples and use cases
ls command tutorial in linux/unix with examples and use cases
rm command tutorial in linux/unix with examples and use cases
df command tutorial in linux/unix with examples and use cases
Linux system directory structure

Add a Comment

Your email address will not be published. Required fields are marked *