rmdir

rmdir linux command cheatsheet by Thamizhiniyan C S

Introduction

This command is used to remove the DIRECTORY(ies), if they are empty.


Syntax

rmdir [OPTION]... DIRECTORY...


Important Flags

FlagDescription

--ignore-fail-on-non-empty

Doesn't show an error message when trying to remove a non-empty directory.

-p

Removes the directory along with its parent in the hierarchy.

-v

Provides a verbose output.

--help

Displays help text.

--version

Displays the command version.


Examples

CommandDescription
rmdir mydir1 mydir2 mydir3 .....

Removes multiple directories using the basic rmdir command.

rmdir LINUX INFO DETAIL

Removes the LINUX, INFO, and DETAIL directories.

rmdir -p mydir1/mydir2/mydir3/...../mydirN

Deletes a directory, including all subdirectories.

rmdir -p LINUX/mydir1/mydir2/mydir3

Deletes the LINUX directory, including all its ancestors.

rmdir -p -v Example/Test

Removes a subdirectory and its hierarchical parent and lists each step of the process.

rmdir -v dir1 dir2 dir3

Displays a message after removing the specified directories.

rmdir -v LINUX INFO DETAIL

Deletes the LINUX, INFO, and DETAIL directories and displays a message after each removal.

rmdir -v LINUX*

Deletes all directories that contain "LINUX" in their name and displays a message after each removal.

rmdir -v Example/Test Example

Removes multiple directories in reverse order of hierarchy and lists each step of the process.

rmdir -v Example*

Removes multiple directories with similar names using wildcards and lists each step of the process.

rmdir --ignore-fail-on-non-empty LINUX

Ignores errors due to non-empty directories when attempting to remove the LINUX directory.

Last updated