1 .\" This manpage is Copyright (C) 1992 Drew Eckhardt;
2 .\" and Copyright (C) 1993 Michael Haardt
3 .\" and Copyright (C) 1993,1994 Ian Jackson
4 .\" and Copyright (C) 2006, 2014 Michael Kerrisk
6 .\" %%%LICENSE_START(GPL_NOVERSION_ONELINE)
7 .\" You may distribute it under the terms of the GNU General
8 .\" Public License. It comes with NO WARRANTY.
11 .TH MKDIR 2 2021-03-22 "Linux" "Linux Programmer's Manual"
13 mkdir, mkdirat \- create a directory
16 .B #include <sys/stat.h>
17 .\" .B #include <unistd.h>
19 .BI "int mkdir(const char *" pathname ", mode_t " mode );
21 .BR "#include <fcntl.h> " "/* Definition of AT_* constants */"
22 .B #include <sys/stat.h>
24 .BI "int mkdirat(int " dirfd ", const char *" pathname ", mode_t " mode );
28 Feature Test Macro Requirements for glibc (see
29 .BR feature_test_macros (7)):
35 _POSIX_C_SOURCE >= 200809L
41 attempts to create a directory named
46 specifies the mode for the new directory (see
48 It is modified by the process's
50 in the usual way: in the absence of a default ACL, the mode of the
52 .RI ( mode " & \(ti" umask " & 0777)."
55 bits are honored for the created directory depends on the operating system.
56 For Linux, see NOTES below.
58 The newly created directory will be owned by the effective user ID of the
60 If the directory containing the file has the set-group-ID
61 bit set, or if the filesystem is mounted with BSD group semantics
62 .RI ( "mount \-o bsdgroups"
64 .IR "mount \-o grpid" ),
65 the new directory will inherit the group ownership from its parent;
66 otherwise it will be owned by the effective group ID of the process.
68 If the parent directory has the set-group-ID bit set, then so will the
69 newly created directory.
75 system call operates in exactly the same way as
77 except for the differences described here.
79 If the pathname given in
81 is relative, then it is interpreted relative to the directory
82 referred to by the file descriptor
84 (rather than relative to the current working directory of
85 the calling process, as is done by
87 for a relative pathname).
97 is interpreted relative to the current working
98 directory of the calling process (like
109 for an explanation of the need for
115 return zero on success.
116 On error, \-1 is returned and
118 is set to indicate the error.
122 The parent directory does not allow write permission to the process,
123 or one of the directories in
125 did not allow search permission.
127 .BR path_resolution (7).)
130 The user's quota of disk blocks or inodes on the filesystem has been
135 already exists (not necessarily as a directory).
136 This includes the case where
138 is a symbolic link, dangling or not.
141 .IR pathname " points outside your accessible address space."
144 The final component ("basename") of the new directory's
147 (e.g., it contains characters not permitted by the underlying filesystem).
150 Too many symbolic links were encountered in resolving
154 The number of links to the parent directory would exceed
158 .IR pathname " was too long."
161 A directory component in
163 does not exist or is a dangling symbolic link.
166 Insufficient kernel memory was available.
169 The device containing
171 has no room for the new directory.
174 The new directory cannot be created because the user's disk quota is
178 A component used as a directory in
180 is not, in fact, a directory.
183 The filesystem containing
185 does not support the creation of directories.
189 refers to a file on a read-only filesystem.
191 The following additional errors can occur for
196 is not a valid file descriptor.
202 is a file descriptor referring to a file other than a directory.
205 was added to Linux in kernel 2.6.16;
206 library support was added to glibc in version 2.4.
209 SVr4, BSD, POSIX.1-2001, POSIX.1-2008.
210 .\" SVr4 documents additional EIO, EMULTIHOP
215 Under Linux, apart from the permission bits, the
220 There are many infelicities in the protocol underlying NFS.
224 On older kernels where
226 is unavailable, the glibc wrapper function falls back to the use of
230 is a relative pathname,
231 glibc constructs a pathname based on the symbolic link in
233 that corresponds to the
247 .BR path_resolution (7)