How to Use the rmdir Command to Remove Empty Directories in Linux
Linuxcommands
The rmdir command in Linux removes one or more empty directories from the system.
The most common options are:
- -p Removes a directory and its subdirectories
- --ignore-fail-on-non-empty Ignores the error if the directory is not empty
Examples:
Removes the favoritos directory:
$ rmdir favoritos
Removes the a/b/c/d subdirectories:
$ rmdir -p a/b/c/d
Tries to remove the musicas directory, but it is not empty:
$ rmdir musicasrmdir: falhou em remover “musicas”: Directory not empty
Learn much more about Linux in our online course. You can enroll here. If you already have an account, or want to create one, just log in or create your user here.
Did you like it? Share
That was just one piece. The course teaches the whole path — from your first command to exam day.