mkdir Command

Purpose

Creates one or more new directories.

Syntax

mkdir [-e] [ -m Mode ] [ -p ] Directory ...

Description

The mkdir command creates one or more new directories specified by the Directory parameter. Each new directory contains the standard entries . (dot) and .. (dot-dot). You can specify the permissions for the new directories with the -m Mode flag. You can use the umask subroutine to set the default mode for the mkdir command.

The owner-ID and group-ID of the new directories are set to the process's effective user-ID and group-ID, respectively. The setgid bit setting is inherited from the parent directory. To change the setgid bit, you can either specify the -m Mode flag or issue the chmod command after the creation of the directory.

Note: To make a new directory you must have write permission in the parent directory.

Flags

Item Description
-e Creates directories with encryption inheritance.
-m Mode Sets the permission bits for the newly-created directories to the value specified by the Mode variable. The Mode variable takes the same values as the Mode parameter for the chmod command, either in symbolic or numeric form.

When you specify the -m flag using symbolic format, the op characters + (plus) and - (minus) are interpreted relative to the assumed permission setting a=rwx. The + adds permissions to the default mode, and the - deletes permissions from the default mode. Refer to the chmodcommand for a complete description of permission bits and formats.

-p Creates missing intermediate path name directories. If the -p flag is not specified, the parent directory of each-newly created directory must already exist.

Intermediate directories are created through the automatic invocation of the following mkdir commands:

mkdir -p -m $(umask -S),u+wx $(dirname Directory) &&
mkdir [-m Mode] Directory

where the [-m Mode] represents any option supplied with your original invocation of the mkdir command.

The mkdir command ignores any Directory parameter that names an existing directory. No error is issued.

Exit Status

This command returns the following exit values:

Item Description
0 All the specified directories were created successfully, or the -p option was specified and all the specified directories now exist.
>0 An error occurred.

Security

Attention RBAC users and Trusted AIX users: This command can perform privileged operations. Only privileged users can run privileged operations. For more information about authorizations and privileges, see Privileged Command Database in AIX® Version 7.1 Security. For a list of privileges and the authorizations associated with this command, see the lssecattr command or the getcmdattr subcommand.

Examples

  1. To create a new directory called Test in the current working directory, enter:
    mkdir Test
    The Test directory is created with default permissions.
  2. To create a new directory called Test with rwxr-xr-x permissions in the previously created /home/demo/sub1 directory, enter:
    mkdir -m 755 /home/demo/sub1/Test
  3. To create a new directory called Test with default permissions in the /home/demo/sub2 directory, enter:
    mkdir -p /home/demo/sub2/Test
    The -p flag creates the /home, /home/demo, and /home/demo/sub2 directories if they do not already exist.

Files

Item Description
/usr/bin/mkdir Contains the mkdir command.