In Linux, the “rmdir” command is used to remove empty directories. It allows you to delete directories that do not contain any files or subdirectories. Here’s how to use the “rmdir” command:
- Open a Terminal:
Launch a terminal emulator on your Linux system.
- Type the “rmdir” command:
Simply type “rmdir” followed by the name or names of the empty directories you want to remove. For example, to delete a directory named “mydir”, run:
If the directory is not empty or if you don’t have the necessary permissions, you’ll receive an error message.
- Delete Multiple Directories:
You can delete multiple empty directories by specifying their names separated by spaces. For example, to delete three directories named “dir1”, “dir2”, and “dir3”, run:
rmdir dir1 dir2 dir3
Note: The “rmdir” command can only delete empty directories. If a directory contains files or other subdirectories, it will not be removed. In such cases, you need to use the “rm” command with the “-r” option to recursively delete directories.
- Verifying the Deletion:
After running the “rmdir” command, you can verify that the directories have been deleted by using the “ls” command to list the contents of the current directory or the relevant directory. For example:
The deleted directories should no longer be listed.
- Exiting the Command:
The “rmdir” command doesn’t produce any output unless there is an error. Once you delete the desired empty directories, you can continue executing other commands or exit the terminal as needed.
It’s important to note that the “rmdir” command can only remove empty directories. If a directory contains files or subdirectories, you need to use the “rm” command with the “-r” option to recursively delete it.