How to use the rmdir command on Ubuntu Linux with examples

|

|

The rmdir command is utilized on Linux systems, specifically on the Ubuntu Linux OS, to remove empty directories. If a directory contains files or other directories, the rmdir command fails. Adjustments can be made by adding command line options, also called switches or flags, to modify the command’s execution or behavior. Options include removing a…

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
–helpUse the –help option to display this help and exit
 –versionUse 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!

Like this:



One response to “How to use the rmdir command on Ubuntu Linux with examples”

  1. no@idontwanthis.com Avatar
    no@idontwanthis.com

    What about directoy and subdirectories

Leave a Reply to no@idontwanthis.com Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.