rmdir command is used remove empty directories from the filesystem in Linux. The rmdir command removes each and every directory specified in the command line only if these directories are empty. So if the specified directory has some directories or files in it then this cannot be removed by rmdir command.
rmdir [-p] [-v | –verbose] [–ignore-fail-on-non-empty] directories …
- –help: It will print the general syntax of the command along with the various options that can be used with the rmdir command as well as give a brief description about each option.
- rmdir -p: In this option each of the directory argument is treated as a pathname of which all components will be removed, if they are already empty, starting from the last component.
- rmdir -v, –verbose: This option displays verbose information for every directory being processed.
- rmdir –ignore-fail-on-non-empty: This option do not report a failure which occurs solely because a directory is non-empty. Normally, when rmdir is being instructed to remove a non-empty directory, it simply reports an error. This option consists of all those error messages.
- rmdir –version: This option is used to display the version information and exit.
Example 1: This will first remove the child directory and then remove the parent directory.
rmdir -p mydir/mydir1
Example 2: Remove the directories mydir1, mydir2, and mydir3, if they are empty. If any of these directories are not empty, then an error message will be printed for that directory, and the other directories will be removed.
rmdir mydir1 mydir2 mydir3
Example 3: Remove the directory mydir/mydir1 if it is empty. Then, remove directory mydir, if it is empty after mydir/mydir1 was removed.
rmdir mydir/mydir1 mydir
- tac command in Linux with Examples
- ed command in Linux with examples
- bc command in Linux with examples
- cvs command in Linux with Examples
- tar command in Linux with examples
- sum command in Linux with Examples
- cd command in Linux with Examples
- ip command in Linux with examples
- w command in Linux with Examples
- tty command in Linux with examples
- cal command in Linux with Examples
- ps command in Linux with Examples
- env command in Linux with Examples
- rev command in Linux with Examples
- rm command in Linux with examples
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.