scripts/bash_aliases: tfix
[man-pages.git] / man2 / mkdir.2
blobe4d7d9472f30302a092b797d98110532535bbc0d
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
5 .\"
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.
9 .\" %%%LICENSE_END
10 .\"
11 .TH MKDIR 2 2021-03-22 "Linux" "Linux Programmer's Manual"
12 .SH NAME
13 mkdir, mkdirat \- create a directory
14 .SH SYNOPSIS
15 .nf
16 .B #include <sys/stat.h>
17 .\" .B #include <unistd.h>
18 .PP
19 .BI "int mkdir(const char *" pathname ", mode_t " mode );
20 .PP
21 .BR "#include <fcntl.h>           " "/* Definition of AT_* constants */"
22 .B #include <sys/stat.h>
23 .PP
24 .BI "int mkdirat(int " dirfd ", const char *" pathname ", mode_t " mode );
25 .fi
26 .PP
27 .RS -4
28 Feature Test Macro Requirements for glibc (see
29 .BR feature_test_macros (7)):
30 .RE
31 .PP
32 .BR mkdirat ():
33 .nf
34     Since glibc 2.10:
35         _POSIX_C_SOURCE >= 200809L
36     Before glibc 2.10:
37         _ATFILE_SOURCE
38 .fi
39 .SH DESCRIPTION
40 .BR mkdir ()
41 attempts to create a directory named
42 .IR pathname .
43 .PP
44 The argument
45 .I mode
46 specifies the mode for the new directory (see
47 .BR inode (7)).
48 It is modified by the process's
49 .I umask
50 in the usual way: in the absence of a default ACL, the mode of the
51 created directory is
52 .RI ( mode " & \(ti" umask " & 0777)."
53 Whether other
54 .I mode
55 bits are honored for the created directory depends on the operating system.
56 For Linux, see NOTES below.
57 .PP
58 The newly created directory will be owned by the effective user ID of the
59 process.
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"
63 or, synonymously
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.
67 .PP
68 If the parent directory has the set-group-ID bit set, then so will the
69 newly created directory.
70 .\"
71 .\"
72 .SS mkdirat()
73 The
74 .BR mkdirat ()
75 system call operates in exactly the same way as
76 .BR mkdir (),
77 except for the differences described here.
78 .PP
79 If the pathname given in
80 .I pathname
81 is relative, then it is interpreted relative to the directory
82 referred to by the file descriptor
83 .I dirfd
84 (rather than relative to the current working directory of
85 the calling process, as is done by
86 .BR mkdir ()
87 for a relative pathname).
88 .PP
90 .I pathname
91 is relative and
92 .I dirfd
93 is the special value
94 .BR AT_FDCWD ,
95 then
96 .I pathname
97 is interpreted relative to the current working
98 directory of the calling process (like
99 .BR mkdir ()).
102 .I pathname
103 is absolute, then
104 .I dirfd
105 is ignored.
108 .BR openat (2)
109 for an explanation of the need for
110 .BR mkdirat ().
111 .SH RETURN VALUE
112 .BR mkdir ()
114 .BR mkdirat ()
115 return zero on success.
116 On error, \-1 is returned and
117 .I errno
118 is set to indicate the error.
119 .SH ERRORS
121 .B EACCES
122 The parent directory does not allow write permission to the process,
123 or one of the directories in
124 .I pathname
125 did not allow search permission.
126 (See also
127 .BR path_resolution (7).)
129 .B EDQUOT
130 The user's quota of disk blocks or inodes on the filesystem has been
131 exhausted.
133 .B EEXIST
134 .I pathname
135 already exists (not necessarily as a directory).
136 This includes the case where
137 .I pathname
138 is a symbolic link, dangling or not.
140 .B EFAULT
141 .IR pathname " points outside your accessible address space."
143 .B EINVAL
144 The final component ("basename") of the new directory's
145 .I pathname
146 is invalid
147 (e.g., it contains characters not permitted by the underlying filesystem).
149 .B ELOOP
150 Too many symbolic links were encountered in resolving
151 .IR pathname .
153 .B EMLINK
154 The number of links to the parent directory would exceed
155 .BR LINK_MAX .
157 .B ENAMETOOLONG
158 .IR pathname " was too long."
160 .B ENOENT
161 A directory component in
162 .I pathname
163 does not exist or is a dangling symbolic link.
165 .B ENOMEM
166 Insufficient kernel memory was available.
168 .B ENOSPC
169 The device containing
170 .I pathname
171 has no room for the new directory.
173 .B ENOSPC
174 The new directory cannot be created because the user's disk quota is
175 exhausted.
177 .B ENOTDIR
178 A component used as a directory in
179 .I pathname
180 is not, in fact, a directory.
182 .B EPERM
183 The filesystem containing
184 .I pathname
185 does not support the creation of directories.
187 .B EROFS
188 .I pathname
189 refers to a file on a read-only filesystem.
191 The following additional errors can occur for
192 .BR mkdirat ():
194 .B EBADF
195 .I dirfd
196 is not a valid file descriptor.
198 .B ENOTDIR
199 .I pathname
200 is relative and
201 .I dirfd
202 is a file descriptor referring to a file other than a directory.
203 .SH VERSIONS
204 .BR mkdirat ()
205 was added to Linux in kernel 2.6.16;
206 library support was added to glibc in version 2.4.
207 .SH CONFORMING TO
208 .BR mkdir ():
209 SVr4, BSD, POSIX.1-2001, POSIX.1-2008.
210 .\" SVr4 documents additional EIO, EMULTIHOP
212 .BR mkdirat ():
213 POSIX.1-2008.
214 .SH NOTES
215 Under Linux, apart from the permission bits, the
216 .B S_ISVTX
217 .I mode
218 bit is also honored.
220 There are many infelicities in the protocol underlying NFS.
221 Some of these affect
222 .BR mkdir ().
223 .SS Glibc notes
224 On older kernels where
225 .BR mkdirat ()
226 is unavailable, the glibc wrapper function falls back to the use of
227 .BR mkdir ().
228 When
229 .I pathname
230 is a relative pathname,
231 glibc constructs a pathname based on the symbolic link in
232 .IR /proc/self/fd
233 that corresponds to the
234 .IR dirfd
235 argument.
236 .SH SEE ALSO
237 .BR mkdir (1),
238 .BR chmod (2),
239 .BR chown (2),
240 .BR mknod (2),
241 .BR mount (2),
242 .BR rmdir (2),
243 .BR stat (2),
244 .BR umask (2),
245 .BR unlink (2),
246 .BR acl (5),
247 .BR path_resolution (7)