WebMasterCampus
WEB DEVELOPER Resources

Linux rmdir Command

Learn Linux rmdir Command with example


Linux rmdir Command

In Linux we can use “rmdir” command to delete empty directories.

rmdir command Syntax

>> rmdir webmastercampus

Note: If the directory is not empty, you will get the following error:

>> rmdir: failed to remove 'webmastercampus': No such file or directory

Removing Directories with rm

rm is a command-line utility for deleting files and directories. Unlike rmdir the rm command can delete both empty and non-empty directories. By default, when used without any option rm does not remove directories.

To delete an empty directory, use the -d (–dir) option and to delete a non-empty directory, and all of its contents use the -r (–recursive or -R) option.

Delete Non-Empty Directories

>> rm -r webmastercampus

Delete write-protected Directories without prompt

If a directory or a file within the directory is write-protected, you will be prompted to confirm the deletion. To remove a directory without being prompted, use the -f option:

>> rm -rf dir1

rmdir Command in Linux (Documentation)

NAME
       rmdir - remove empty directories

SYNOPSIS
       rmdir [OPTION]... DIRECTORY...

DESCRIPTION
       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
Created with love and passion.