Understanding the rmdir Command

Basic Usage of rmdir

The rmdir command is used to remove empty directories in Linux. The most basic form of the command is:

rmdir [directory_name]

This will remove the specified directory if it is empty.

Options Available with rmdir

rmdir (Basic Usage)

Removes an empty directory:

rmdir empty_folder

rmdir -p (Remove Parent Directories)

Removes the directory and its parent directories, but only if they are empty:

rmdir -p /home/user/dir1/dir2

rmdir --ignore-fail-on-non-empty (Ignore Non-empty Errors)

Ignores errors when trying to remove non-empty directories:

rmdir --ignore-fail-on-non-empty non_empty_folder

rmdir --help (Show Help)

Displays help information for the rmdir command:

rmdir --help

Summary of Options

Option Description
rmdir [directory_name] Removes an empty directory.
rmdir -p [path] Removes a directory and any parent directories if they are empty.
rmdir --ignore-fail-on-non-empty Ignores errors for non-empty directories.
rmdir --help Displays help information.

Manual Pages

For more detailed information, use the manual page for the rmdir command:

man rmdir