Linux rmdir command

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:

  1. Open a Terminal:
    Launch a terminal emulator on your Linux system.
  2. 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:
   rmdir mydir

If the directory is not empty or if you don’t have the necessary permissions, you’ll receive an error message.

  1. 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.

  1. 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:
   ls

The deleted directories should no longer be listed.

  1. 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.