The rmdir
command in Linux is used to delete empty directories (folders). It only deletes directories that do not contain any subdirectories or files. If a directory is not empty, rmdir
will display an error message and will not delete it.
Using the rmdir command:
rmdir <director_name>
Example:
rmdir directory_name
Some options for the rmdir command are:
-p
: allows you to delete a directory and its parent directories if they remain empty after deletion. --ignore-fail-on-non-empty
: allows you to ignore an error message if the directory is not empty. --verbose
: displays detailed information about the directory deletion process.There is no need to install the rmdir
command, as it is built-in to most Linux distributions.
If for some reason the rmdir
command is missing or unavailable on your system, you can install it as follows:
sudo apt-get install coreutils
sudo dnf install coreutils
or sudo yum install coreutils
sudo pacman -S coreutils
Note that the rmdir
command may also be available in other packages, so you can use your distribution's package manager to find and install a package containing this command.