Linux rmdir command

|

What is the rmdir Command?

The rmdir command is used to remove only empty directories. You can remove one or multiple empty directories at the same time. It can also remove directories located inside other directories if you provide their full path.

Syntax:

rmdir [option] directory_name

Options

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

Example 1: Remove an empty directory


Command:

rmdir myfolder

Output:

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

Example 2: Remove Multiple Empty Directories


Command:

rmdir -p dir1/dir2/dir3

Output:

(No output)

Explanation:

If dir3, dir2, and dir1 are empty, they are deleted successfully. If any directory is not empty, the following error appears:

rmdir: failed to remove 'dir2': Directory not empty

ONLINE WEB TOOLS

WhatIsMyIpAddress
Shorterner