1 .\" This manpage is Copyright (C) 1992 Drew Eckhardt;
2 .\" and Copyright (C) 1993 Michael Haardt;
3 .\" and Copyright (C) 1993,1995 Ian Jackson
4 .\" and Copyright (C) 2006, 2014 Michael Kerrisk
6 .\" %%%LICENSE_START(VERBATIM)
7 .\" Permission is granted to make and distribute verbatim copies of this
8 .\" manual provided the copyright notice and this permission notice are
9 .\" preserved on all copies.
11 .\" Permission is granted to copy and distribute modified versions of this
12 .\" manual under the conditions for verbatim copying, provided that the
13 .\" entire resulting derived work is distributed under the terms of a
14 .\" permission notice identical to this one.
16 .\" Since the Linux kernel and libraries are constantly changing, this
17 .\" manual page may be incorrect or out-of-date. The author(s) assume no
18 .\" responsibility for errors or omissions, or for damages resulting from
19 .\" the use of the information contained herein. The author(s) may not
20 .\" have taken the same level of care in the production of this manual,
21 .\" which is licensed free of charge, as they might when working
24 .\" Formatted or processed versions of this manual, if unaccompanied by
25 .\" the source, must acknowledge the copyright and authors of this work.
28 .\" Modified Sat Jul 24 00:35:52 1993 by Rik Faith <faith@cs.unc.edu>
29 .\" Modified Thu Jun 4 12:21:13 1998 by Andries Brouwer <aeb@cwi.nl>
30 .\" Modified Thu Mar 3 09:49:35 2005 by Michael Haardt <michael@moria.de>
31 .\" 2007-03-25, mtk, added various text to DESCRIPTION.
33 .TH RENAME 2 2014-02-21 "Linux" "Linux Programmer's Manual"
35 rename, renameat \- change the name or location of a file
40 .BI "int rename(const char *" oldpath ", const char *" newpath );
42 .BR "#include <fcntl.h> " "/* Definition of AT_* constants */"
45 .BI "int renameat(int " olddirfd ", const char *" oldpath ,
46 .BI " int " newdirfd ", const char *" newpath );
50 Feature Test Macro Requirements for glibc (see
51 .BR feature_test_macros (7)):
60 _XOPEN_SOURCE\ >=\ 700 || _POSIX_C_SOURCE\ >=\ 200809L
69 renames a file, moving it between directories if required.
70 Any other hard links to the file (as created using
73 Open file descriptors for
79 already exists, it will be atomically replaced (subject to
80 a few conditions; see ERRORS below), so that there is
81 no point at which another process attempting to access
89 are existing hard links referring to the same file, then
91 does nothing, and returns a success status.
95 exists but the operation fails for some reason,
97 guarantees to leave an instance of
102 can specify a directory.
105 must either not exist, or it must specify an empty directory.
107 However, when overwriting there will probably be a window in which
112 refer to the file being renamed.
116 refers to a symbolic link, the link is renamed; if
118 refers to a symbolic link, the link will be overwritten.
122 system call operates in exactly the same way as
124 except for the differences described here.
126 If the pathname given in
128 is relative, then it is interpreted relative to the directory
129 referred to by the file descriptor
131 (rather than relative to the current working directory of
132 the calling process, as is done by
134 for a relative pathname).
144 is interpreted relative to the current working
145 directory of the calling process (like
154 The interpretation of
158 except that a relative pathname is interpreted relative
159 to the directory referred to by the file descriptor
164 for an explanation of the need for
167 On success, zero is returned.
168 On error, \-1 is returned, and
170 is set appropriately.
174 Write permission is denied for the directory containing
178 or, search permission is denied for one of the directories
179 in the path prefix of
185 is a directory and does not allow write permission (needed to update
190 .BR path_resolution (7).)
193 The rename fails because
194 .IR oldpath " or " newpath
195 is a directory that is in use by some process (perhaps as
196 current working directory, or as root directory, or because
197 it was open for reading) or is in use by the system
198 (for example as mount point), while the system considers
200 (Note that there is no requirement to return
203 cases\(emthere is nothing wrong with doing the rename anyway\(embut
204 it is allowed to return
206 if the system cannot otherwise
207 handle such situations.)
210 The user's quota of disk blocks on the filesystem has been exhausted.
213 .IR oldpath " or " newpath " points outside your accessible address space."
216 The new pathname contained a path prefix of the old, or, more generally,
217 an attempt was made to make a directory a subdirectory of itself.
221 is an existing directory, but
226 Too many symbolic links were encountered in resolving
227 .IR oldpath " or " newpath .
231 already has the maximum number of links to it, or
232 it was a directory and the directory containing
234 has the maximum number of links.
237 .IR oldpath " or " newpath " was too long."
243 or, a directory component in
253 Insufficient kernel memory was available.
256 The device containing the file has no room for the new directory
260 A component used as a directory in
261 .IR oldpath " or " newpath
262 is not, in fact, a directory.
267 exists but is not a directory.
269 .BR ENOTEMPTY " or " EEXIST
271 is a nonempty directory, that is, contains entries other than "." and "..".
273 .BR EPERM " or " EACCES
274 The directory containing
278 set and the process's effective user ID is neither
279 the user ID of the file to be deleted nor that of the directory
280 containing it, and the process is not privileged
281 (Linux: does not have the
286 is an existing file and the directory containing it has the sticky bit set
287 and the process's effective user ID is neither the user ID of the file
288 to be replaced nor that of the directory containing it,
289 and the process is not privileged
290 (Linux: does not have the
293 or the filesystem containing
295 does not support renaming of the type requested.
298 The file is on a read-only filesystem.
301 .IR oldpath " and " newpath
302 are not on the same mounted filesystem.
303 (Linux permits a filesystem to be mounted at multiple points, but
305 does not work across different mount points,
306 even if the same filesystem is mounted on both.)
308 The following additional errors can occur for
315 is not a valid file descriptor.
321 is a file descriptor referring to a file other than a directory;
328 was added to Linux in kernel 2.6.16;
329 library support was added to glibc in version 2.4.
332 4.3BSD, C89, C99, POSIX.1-2001, POSIX.1-2008.
337 On NFS filesystems, you can not assume that if the operation
338 failed, the file was not renamed.
339 If the server does the rename operation
340 and then crashes, the retransmitted RPC which will be processed when the
341 server is up again causes a failure.
342 The application is expected to
346 for a similar problem.
353 .BR path_resolution (7),
356 This page is part of release 3.65 of the Linux
359 A description of the project,
360 and information about reporting bugs,
362 \%http://www.kernel.org/doc/man\-pages/.