To remove empty directories in Unix-like operating systems, you can use the rmdir command. This command only works on directories that are empty. Here’s how to use it:
- To remove an empty directory, use:
rmdir directory_name
If the directory is empty, it will be removed successfully. If the directory is not empty, you will receive an error message indicating that the directory is not empty.
-
If you want to remove multiple empty directories at once, you can specify them all in the command:
rmdir dir1 dir2 dir3 -
To check if a directory is empty before removing it, you can list its contents:
ls directory_name
If you need to remove a directory and its contents (including non-empty directories), you would use the rm -r command instead, but be cautious as it will delete everything inside the directory.
