A Guide to the rmdir Command in Linux: Removing Folders
The rmdir
command is used to delete folders in a Linux environment. Similar to how you can create a folder using the mkdir
command, you can remove a folder using rmdir
. Let’s take a closer look at how this command works.
To delete a single folder, you can use the following command:
1 | mkdir fruits |
This will create a folder called “fruits” and then remove it.
If you have multiple folders that you want to delete, you can do so in one go. Here’s an example:
1 | mkdir fruits cars |
This command will create two folders, “fruits” and “cars”, and then delete both of them.
It’s important to note that the folder you want to delete must be empty. If the folder contains files, you cannot use rmdir
. Instead, you can use the more versatile rm
command with the -rf
options. For example:
1 | rm -rf fruits cars |
This command will delete the folders “fruits” and “cars” along with any files they contain. Be cautious when using the rm
command with the -rf
options, as it does not prompt for confirmation and will immediately remove everything you specify.
Keep in mind that once you delete files using command line tools, such as rmdir
or rm
, they are not sent to the recycle bin and recovering lost files can be challenging.
It’s worth mentioning that the rmdir
command works not only on Linux but also on macOS, WSL (Windows Subsystem for Linux), and any other UNIX-like environment.
tags: [“Linux commands”, “rmdir”, “deleting folders”, “command line”, “UNIX”]