rmdir Command

Purpose

Removes a directory.

Syntax

rmdir [ -p ] Directory ...

Description

The rmdir command removes the directory that is specified by the Directory variable from the system. The directory must be empty before you can remove it. Also, you must have write permission in its parent directory. Use the ls -al command to check whether the directory is empty. The directory must not be exported for use by the NFS version 4 server.
Note: The rmdir command supports the -- (dash, dash) parameter as a delimiter that indicates the end of the flags.

Flags

Table 1. Flags
Item Description
-p Directory Removes all the directories along the path name that is specified by the Directory variable. The directory that is specified by the Directory variable must be empty and the user must have write permission in the parent directory before they can be removed.

Exit status

This command returns the following exit values:

Table 2. Exit status
Item Description
0 Each directory entry that is specified by the Directory variable is removed successfully.
>0 An error occurred.

Examples

  1. To empty and remove a directory, enter the following command:
    rm mydir/* mydir/.*
    rmdir mydir
    This command removes the contents of the mydir directory and then removes the empty directory. The rm command displays an error message when you try to remove the . (dot) and .. (dot, dot) directories. However, the rmdir command removes the . (dot) and .. (dot, dot) directories. 

    The rm mydir/* mydir/.* command first removes files with names that do not begin with a dot, and then removes the directories with names that begin with a dot. The ls command does not list file names that begin with a dot, unless you use the -a flag.

  2. To remove the /home/pvcroot/mydir directory, enter the following command:
    rmdir -p /home/pvcroot/mydir
    This command removes the /mydir directory from the home directory of the current user. For example, pvcroot directory. You cannot remove the /home or /home/pvcroot directories. If a directory does not have write permission, the rmdir command exits.