1MKDIR(1P) POSIX Programmer's Manual MKDIR(1P)
2
3
4
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
12 mkdir — make directories
13
15 mkdir [-p] [-m mode] dir...
16
18 The mkdir utility shall create the directories specified by the oper‐
19 ands, in the order specified.
20
21 For each dir operand, the mkdir utility shall perform actions equiva‐
22 lent to the mkdir() function defined in the System Interfaces volume of
23 POSIX.1‐2017, called with the following arguments:
24
25 1. The dir operand is used as the path argument.
26
27 2. The value of the bitwise-inclusive OR of S_IRWXU, S_IRWXG, and
28 S_IRWXO is used as the mode argument. (If the -m option is speci‐
29 fied, the value of the mkdir() mode argument is unspecified, but
30 the directory shall at no time have permissions less restrictive
31 than the -m mode option-argument.)
32
34 The mkdir utility shall conform to the Base Definitions volume of
35 POSIX.1‐2017, Section 12.2, Utility Syntax Guidelines.
36
37 The following options shall be supported:
38
39 -m mode Set the file permission bits of the newly-created directory
40 to the specified mode value. The mode option-argument shall
41 be the same as the mode operand defined for the chmod util‐
42 ity. In the symbolic_mode strings, the op characters '+' and
43 '-' shall be interpreted relative to an assumed initial mode
44 of a=rwx; '+' shall add permissions to the default mode, '-'
45 shall delete permissions from the default mode.
46
47 -p Create any missing intermediate pathname components.
48
49 For each dir operand that does not name an existing direc‐
50 tory, before performing the actions described in the DESCRIP‐
51 TION above, the mkdir utility shall create any pathname com‐
52 ponents of the path prefix of dir that do not name an exist‐
53 ing directory by performing actions equivalent to first call‐
54 ing the mkdir() function with the following arguments:
55
56 1. A pathname naming the missing pathname component, ending
57 with a trailing <slash> character, as the path argument
58
59 2. The value zero as the mode argument
60
61 and then calling the chmod() function with the following
62 arguments:
63
64 1. The same path argument as in the mkdir() call
65
66 2. The value (S_IWUSR|S_IXUSR|~filemask)&0777 as the mode
67 argument, where filemask is the file mode creation mask
68 of the process (see the System Interfaces volume of
69 POSIX.1‐2017, umask())
70
71 Each dir operand that names an existing directory shall be
72 ignored without error.
73
75 The following operand shall be supported:
76
77 dir A pathname of a directory to be created.
78
80 Not used.
81
83 None.
84
86 The following environment variables shall affect the execution of
87 mkdir:
88
89 LANG Provide a default value for the internationalization vari‐
90 ables that are unset or null. (See the Base Definitions vol‐
91 ume of POSIX.1‐2017, Section 8.2, Internationalization Vari‐
92 ables for the precedence of internationalization variables
93 used to determine the values of locale categories.)
94
95 LC_ALL If set to a non-empty string value, override the values of
96 all the other internationalization variables.
97
98 LC_CTYPE Determine the locale for the interpretation of sequences of
99 bytes of text data as characters (for example, single-byte as
100 opposed to multi-byte characters in arguments).
101
102 LC_MESSAGES
103 Determine the locale that should be used to affect the format
104 and contents of diagnostic messages written to standard
105 error.
106
107 NLSPATH Determine the location of message catalogs for the processing
108 of LC_MESSAGES.
109
111 Default.
112
114 Not used.
115
117 The standard error shall be used only for diagnostic messages.
118
120 None.
121
123 None.
124
126 The following exit values shall be returned:
127
128 0 All the specified directories were created successfully, or the
129 -p option was specified and all the specified directories either
130 already existed or were created successfully.
131
132 >0 An error occurred.
133
135 Default.
136
137 The following sections are informative.
138
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
152 None.
153
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‐2017. 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
172 None.
173
175 chmod, rm, rmdir, umask
176
177 The Base Definitions volume of POSIX.1‐2017, Chapter 8, Environment
178 Variables, Section 12.2, Utility Syntax Guidelines
179
180 The System Interfaces volume of POSIX.1‐2017, mkdir(), umask()
181
183 Portions of this text are reprinted and reproduced in electronic form
184 from IEEE Std 1003.1-2017, Standard for Information Technology -- Por‐
185 table Operating System Interface (POSIX), The Open Group Base Specifi‐
186 cations Issue 7, 2018 Edition, Copyright (C) 2018 by the Institute of
187 Electrical and Electronics Engineers, Inc and The Open Group. In the
188 event of any discrepancy between this version and the original IEEE and
189 The Open Group Standard, the original IEEE and The Open Group Standard
190 is the referee document. The original Standard can be obtained online
191 at http://www.opengroup.org/unix/online.html .
192
193 Any typographical or formatting errors that appear in this page are
194 most likely to have been introduced during the conversion of the source
195 files to man page format. To report such errors, see https://www.ker‐
196 nel.org/doc/man-pages/reporting_bugs.html .
197
198
199
200IEEE/The Open Group 2017 MKDIR(1P)