The rmdir command is used to remove empty directories on Linux systems.
The rmdir command is used on Ubuntu Linux to remove empty directories or folders. When you delete a directory using the rmdir command, the directory must be empty. If the directory contains any files, subdirectories, or hidden files, the rmdir command will fail.
The rmdir command is useful when cleaning up your file system and removing empty directories that are no longer needed. It’s also a useful command for scripting and automation tasks in Linux.
When you’re ready to learn how to use the rmdir commands, follow the guide below:
About the rmdir command:
The rmdir command is used to remove empty directories on Linux systems. If the directory you wish to delete isn’t empty, the rmdir command will fail. It’s the same as using your mouse to right-click a directory or folder and select delete. The rmdir is the way to do it on the command line.
Only directories with no files or other directories can be removed using the rmdir command.
Syntax:
The syntax is the rule and format of how the rmdir command can be used. The syntax options can be reordered. But a straight format must be followed.,.
Below is an example syntax of how to use the rmdir command.
rmdir [OPTION]. DIRECTORY.
Options:
The command line options are switches or flags that determine how the commands are executed or controlled. They modify the behavior of the commands. They are separated by spaces and followed after the commands.
Below are some options for the rmdir command:
DIRECTORY. | Replace DIRECTORY.. with the directory you want to remove or delete. |
-p, –parents | Remove DIRECTORY and its ancestors. e.g., ‘rmdir -p a/b/c’ is similar to ‘rmdir a/b/c a/b a’ |
-v, –verbose | Use the -v or –verbose option to output a diagnostic for every directory processed |
–help | Use the –help option to display this help and exit |
–version | Use the –version option to output version information and exit. |
Examples:
Below are some examples of how to run and use the rmdir on Ubuntu Linux.
You will run the commands below if you want to delete or remove an empty directory or folder called Confidential.
rmdir Confidential
Run the commands below to remove multiple empty directories or folders called Bank, Statements, and Deposits.
rmdir Bank Statements Deposits
If you’re not logged in as a root account, you may have to use the sudo command.
sudo rmdir Bank Statements Deposits
To remove an empty sub-directory, run the commands below.
sudo rmdir directory/sub_directory
When you run rmdir with the –help option, you’ll see the help text below:
Usage: rmdir [OPTION]. DIRECTORY. Remove the DIRECTORY(ies), if they are empty. --ignore-fail-on-non-empty ignore each failure that is solely because a directory is non-empty -p, --parents remove DIRECTORY and its ancestors; e.g., 'rmdir -p a/b/c' is similar to 'rmdir a/b/c a/b a' -v, --verbose output a diagnostic for every directory processed --help display this help and exit --version output version information and exit
That’s it!
I hope you like it, and please come back soon for more Ubuntu Linux commands!
Leave a Reply Cancel reply