In this article, we will see Linux rmdir command with examples. Linux rmdir command is used remove empty directories from the file system. If the specified directory has some directories or files in it then this cannot be removed by rmdir command.
Syntax:
rmdir [OPTION]... DIRECTORY...
Linux rmdir with examples
1. Remove the directory backup. Where -v prints the output message of the command
rmdir backup -v
2. To delete parent directories of a directory.
[root@master r2schools]# rmdir -p hr/USA/INDIA/BRAZIL -v rmdir: removing directory, 'hr/USA/INDIA/BRAZIL' rmdir: removing directory, 'hr/USA/INDIA' rmdir: removing directory, 'hr/USA' rmdir: removing directory, 'hr'
3. Remove the directories sales and accounts if they are empty.
rmdir sales accounts
4. To ignore to remove non-empty directories using rmdir command.
rmdir --ignore-fail-on-non-empty hr/