Remove a Directory in Bash

Here, you will learn how to remove directories in bash.

rmdir

Definition:

rmdir is the opposite of mkdir. It is used to remove the directory name given in the argument. This command is mainly used to remove empty directories. Just like you can make muliple directories at the same time, you can also delete multiple directories simultaneously by passing their names as arguments.

Syntax:

rmdir [option] [dir_name]

Options:

rmdir in terminal can take two options:

Option Meaning
-p This option tells rmdir to remove nested directories if they become empty after deleting previous directory
-v or verbose Verbose mode outputs after every directory operation that you perform

Example:

rmdir my_dir_1 my_dir_2 my_dir_3

Get hands-on with 1200+ tech skills courses.