1MKDIR(1P)                  POSIX Programmer's Manual                 MKDIR(1P)
2
3
4

PROLOG

6       This  manual  page is part of the POSIX Programmer's Manual.  The Linux
7       implementation of this interface may differ (consult the  corresponding
8       Linux  manual page for details of Linux behavior), or the interface may
9       not be implemented on Linux.
10
11

NAME

13       mkdir — make directories
14

SYNOPSIS

16       mkdir [−p] [−m mode] dir...
17

DESCRIPTION

19       The mkdir utility shall create the directories specified by  the  oper‐
20       ands, in the order specified.
21
22       For  each  dir operand, the mkdir utility shall perform actions equiva‐
23       lent to the mkdir() function defined in the System Interfaces volume of
24       POSIX.1‐2008, called with the following arguments:
25
26        1. The dir operand is used as the path argument.
27
28        2. The  value  of  the  bitwise-inclusive  OR of S_IRWXU, S_IRWXG, and
29           S_IRWXO is used as the mode argument. (If the −m option  is  speci‐
30           fied,  the  value  of the mkdir() mode argument is unspecified, but
31           the directory shall at no time have  permissions  less  restrictive
32           than the −m mode option-argument.)
33

OPTIONS

35       The  mkdir  utility  shall  conform  to  the Base Definitions volume of
36       POSIX.1‐2008, Section 12.2, Utility Syntax Guidelines.
37
38       The following options shall be supported:
39
40       −m mode   Set the file permission bits of the  newly-created  directory
41                 to  the  specified mode value. The mode option-argument shall
42                 be the same as the mode operand defined for the  chmod  util‐
43                 ity.  In the symbolic_mode strings, the op characters '+' and
44                 '−' shall be interpreted relative to an assumed initial  mode
45                 of  a=rwx; '+' shall add permissions to the default mode, '−'
46                 shall delete permissions from the default mode.
47
48       −p        Create any missing intermediate pathname components.
49
50                 For each dir operand that does not name  an  existing  direc‐
51                 tory, before performing the actions described in the DESCRIP‐
52                 TION above, the mkdir utility shall create any pathname  com‐
53                 ponents  of the path prefix of dir that do not name an exist‐
54                 ing directory by performing actions equivalent to first call‐
55                 ing the mkdir() function with the following arguments:
56
57                  1. A  pathname naming the missing pathname component, ending
58                     with a trailing <slash> character, as the path argument
59
60                  2. The value zero as the mode argument
61
62                 and then calling the  chmod()  function  with  the  following
63                 arguments:
64
65                  1. The same path argument as in the mkdir() call
66
67                  2. The  value  (S_IWUSR|S_IXUSR|~filemask)&0777  as the mode
68                     argument, where filemask is the file mode  creation  mask
69                     of  the  process  (see  the  System  Interfaces volume of
70                     POSIX.1‐2008, umask())
71
72                 Each dir operand that names an existing  directory  shall  be
73                 ignored without error.
74

OPERANDS

76       The following operand shall be supported:
77
78       dir       A pathname of a directory to be created.
79

STDIN

81       Not used.
82

INPUT FILES

84       None.
85

ENVIRONMENT VARIABLES

87       The  following  environment  variables  shall  affect  the execution of
88       mkdir:
89
90       LANG      Provide a default value for  the  internationalization  vari‐
91                 ables  that are unset or null. (See the Base Definitions vol‐
92                 ume of POSIX.1‐2008, Section 8.2, Internationalization  Vari‐
93                 ables  for  the  precedence of internationalization variables
94                 used to determine the values of locale categories.)
95
96       LC_ALL    If set to a non-empty string value, override  the  values  of
97                 all the other internationalization variables.
98
99       LC_CTYPE  Determine  the  locale for the interpretation of sequences of
100                 bytes of text data as characters (for example, single-byte as
101                 opposed to multi-byte characters in arguments).
102
103       LC_MESSAGES
104                 Determine the locale that should be used to affect the format
105                 and contents  of  diagnostic  messages  written  to  standard
106                 error.
107
108       NLSPATH   Determine the location of message catalogs for the processing
109                 of LC_MESSAGES.
110

ASYNCHRONOUS EVENTS

112       Default.
113

STDOUT

115       Not used.
116

STDERR

118       The standard error shall be used only for diagnostic messages.
119

OUTPUT FILES

121       None.
122

EXTENDED DESCRIPTION

124       None.
125

EXIT STATUS

127       The following exit values shall be returned:
128
129        0    All the specified directories were created successfully or the −p
130             option was specified and all the specified directories now exist.
131
132       >0    An error occurred.
133

CONSEQUENCES OF ERRORS

135       Default.
136
137       The following sections are informative.
138

APPLICATION USAGE

140       The  default  file  mode for directories is a=rwx (777 on most systems)
141       with selected permissions removed in accordance with the file mode cre‐
142       ation  mask. For intermediate pathname components created by mkdir, the
143       mode is the default modified by u+wx so  that  the  subdirectories  can
144       always be created regardless of the file mode creation mask; if differ‐
145       ent ultimate permissions are desired for the intermediate  directories,
146       they can be changed afterwards with chmod.
147
148       Note  that some of the requested directories may have been created even
149       if an error occurs.
150

EXAMPLES

152       None.
153

RATIONALE

155       The System V −m option was included to control the file mode.
156
157       The System V −p option was included to create any  needed  intermediate
158       directories  and  to complement the functionality provided by rmdir for
159       removing directories in the path prefix as they become empty.   Because
160       no  error  is  produced  if  any  path component already exists, the −p
161       option is also useful to ensure that a particular directory exists.
162
163       The functionality of mkdir is described substantially through a  refer‐
164       ence  to  the  mkdir()  function  in  the  System  Interfaces volume of
165       POSIX.1‐2008. For example, by default, the mode  of  the  directory  is
166       affected  by  the file mode creation mask in accordance with the speci‐
167       fied behavior of the mkdir() function.  In  this  way,  there  is  less
168       duplication  of effort required for describing details of the directory
169       creation.
170

FUTURE DIRECTIONS

172       None.
173

SEE ALSO

175       chmod, rm, rmdir, umask
176
177       The Base Definitions volume of  POSIX.1‐2008,  Chapter  8,  Environment
178       Variables, Section 12.2, Utility Syntax Guidelines
179
180       The System Interfaces volume of POSIX.1‐2008, mkdir(), umask()
181
183       Portions  of  this text are reprinted and reproduced in electronic form
184       from IEEE Std 1003.1, 2013 Edition, Standard for Information Technology
185       --  Portable  Operating  System  Interface (POSIX), The Open Group Base
186       Specifications Issue 7, Copyright (C) 2013 by the Institute of Electri‐
187       cal  and  Electronics  Engineers,  Inc  and  The  Open Group.  (This is
188       POSIX.1-2008 with the 2013 Technical Corrigendum  1  applied.)  In  the
189       event of any discrepancy between this version and the original IEEE and
190       The Open Group Standard, the original IEEE and The Open Group  Standard
191       is  the  referee document. The original Standard can be obtained online
192       at http://www.unix.org/online.html .
193
194       Any typographical or formatting errors that appear  in  this  page  are
195       most likely to have been introduced during the conversion of the source
196       files to man page format. To report such errors,  see  https://www.ker
197       nel.org/doc/man-pages/reporting_bugs.html .
198
199
200
201IEEE/The Open Group                  2013                            MKDIR(1P)
Impressum