The Single UNIX ® Specification, Version 2
Copyright © 1997 The Open Group


mkdir - make directories


mkdir [-p][-m mode] dir...


The mkdir utility will create the directories specified by the operands, in the order specified.

For each dir operand, the mkdir utility will perform actions equivalent to the XSH specification mkdir() function, called with the following arguments:

  1. The dir operand is used as the path argument.

  2. The value of the bitwise inclusive OR of S_IRWXU, S_IRWXG and S_IRWXO is used as the mode argument. (If the -m option is specified, the mode option-argument overrides this default.)


The mkdir utility supports the XBD specification, Utility Syntax Guidelines  .

The following options are supported:

-m mode
Set the file permission bits of the newly-created directory to the specified mode value. The mode option-argument will be the same as the mode operand defined for the chmod utility. In the symbolic_mode strings, the op characters "+" and "-" will be interpreted relative to an assumed initial mode of a=rwx; "+" will add permissions to the default mode, "-" will delete permissions from the default mode.
Create any missing intermediate pathname components. For each dir operand that does not name an existing directory, effects equivalent to those caused by the following command will occur:

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

where the [-m mode] option represents that option supplied to the original invocation of mkdir, if any. Each dir operand that names an existing directory will be ignored without error.


The following operand is supported:
A pathname of a directory to be created.


Not used.




The following environment variables affect the execution of mkdir:
Provide a default value for the internationalisation variables that are unset or null. If LANG is unset or null, the corresponding value from the implementation-dependent default locale will be used. If any of the internationalisation variables contains an invalid setting, the utility will behave as if none of the variables had been defined.
If set to a non-empty string value, override the values of all the other internationalisation variables.
Determine the locale for the interpretation of sequences of bytes of text data as characters (for example, single- as opposed to multi-byte characters in arguments).
Determine the locale that should be used to affect the format and contents of diagnostic messages written to standard error.
Determine the location of message catalogues for the processing of LC_MESSAGES .




Not used.


Used only for diagnostic messages.






The following exit values are returned:
All the specified directories were created successfully or the -p option was specified and all the specified directories now exist.
An error occurred.




The default file mode for directories is a=rwx (777 on most systems) with selected permissions removed in accordance with the file mode creation mask. For intermediate pathname components created by mkdir, the mode is the default modified by u+wx so that the subdirectories can always be created regardless of the file mode creation mask; if different ultimate permissions are desired for the intermediate directories, they can be changed afterwards with chmod.

Note that some of the requested directories may have been created even if an error occurs.




The IEEE PASC 1003.2 Interpretations Committee has forwarded concerns about parts of this interface definition to the IEEE PASC Shell and Utilities Working Group which is identifying the corrections. A future revision of this specification will align with IEEE Std. 1003.2b when finalised.


rm, rmdir, umask, the XSH specification description of mkdir().

UNIX ® is a registered Trademark of The Open Group.
Copyright © 1997 The Open Group
[ Main Index | XSH | XCU | XBD | XCURSES | XNS ]