mkdir — Make a directory

Format

mkdir [–p] [–m mode] directory …

Description

The mkdir command creates a new directory for each named directory argument. The mode for a directory created by mkdir is determined by taking the initial mode setting of 777 (a=rwx) or the value of –m if specified and applying the umask value to it.

Options

–m mode
Lets you specify permissions for the directories. The mode argument can have the same value as the mode for chmod; see chmod for more details.

You can also set the sticky bit on for directories. For more information, see chmod. The umask value is applied to the mode value to determine the new directory's actual mode setting.

Note: A superuser or the file owner can use a chmod command or chmod() function to change two options for an executable file. The options are set in two file mode bits:
  • Set-user-ID (S_ISUID) with the setuid option
  • Set-group-ID (S_ISGID) with the setgid option

If one or both of these bits are on, the effective UID, effective GID, or both, plus the saved UID, saved GID, or both, for the process running the program are changed to the owning UID, GID, or both, for the file. This change temporarily gives the process running the program access to data the file owner or group can access.

In a new file, both bits are set off. Also, if the owning UID or GID of a file is changed or if the file is written in, the bits are turned off. In shell scripts, these bits are ignored.

If the RACF® profile named FILE.GROUPOWNER.SETGID exists in the UNIXPRIV class, then the set-group-ID bit for a directory determines how the group owner is initialized for new objects created within the directory:
  • If the set-gid bit is on, then the owning GID is set to that of the directory.
  • If the set-gid bit is off, then the owning GID is set to the effective GID of the process.
–p
Creates intermediate directory components that don't already exist. For example, if one of the directory arguments is dir/subdir/subsub and subdir doesn't already exist, mkdir creates it. Such intermediate directories are created with mode bits determined in the following way: Take a default mode setting of 777 (a=rwx), apply the process's setting to it, and then turn on the user write and user execute permissions (u+wx). The –m mode specification on the command line is not used for computing the mode of intermediate directories.

Localization

mkdir uses the following localization environment variables:
  • LANG
  • LC_ALL
  • LC_CTYPE
  • LC_MESSAGES
  • NLSPATH

See Localization for more information.

Exit values

0
Successful completion
1
Failure due to any of the following:
  • Missing mode after –m
  • Incorrect mode
  • Incorrect command-line option
  • Missing directory name
  • Inability to create the directory

Messages

Possible error messages include:
Path not found
The preceding structure (parent directory) of the named directory does not exist.
Access denied
The requested directory already exists or is otherwise inaccessible.
Cannot create directory
Some other error occurred during creation of the directory.

Portability

POSIX.2, X/Open Portability Guide, UNIX systems.

Related information

rm, rmdir,