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-08-19 "Linux" "Linux Programmer's Manual"
35 rename, renameat, renameat2 \- 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 );
48 .BI "int renameat2(int " olddirfd ", const char *" oldpath ,
49 .BI " int " newdirfd ", const char *" newpath \
50 ", unsigned int " flags );
54 Feature Test Macro Requirements for glibc (see
55 .BR feature_test_macros (7)):
64 _XOPEN_SOURCE\ >=\ 700 || _POSIX_C_SOURCE\ >=\ 200809L
68 .\" FIXME . need to define FTMs for renameat2(), once it hits glibc
74 renames a file, moving it between directories if required.
75 Any other hard links to the file (as created using
78 Open file descriptors for
84 already exists, it will be atomically replaced (subject to
85 a few conditions; see ERRORS below), so that there is
86 no point at which another process attempting to access
94 are existing hard links referring to the same file, then
96 does nothing, and returns a success status.
100 exists but the operation fails for some reason,
102 guarantees to leave an instance of
107 can specify a directory.
110 must either not exist, or it must specify an empty directory.
112 However, when overwriting there will probably be a window in which
117 refer to the file being renamed.
121 refers to a symbolic link, the link is renamed; if
123 refers to a symbolic link, the link will be overwritten.
127 system call operates in exactly the same way as
129 except for the differences described here.
131 If the pathname given in
133 is relative, then it is interpreted relative to the directory
134 referred to by the file descriptor
136 (rather than relative to the current working directory of
137 the calling process, as is done by
139 for a relative pathname).
149 is interpreted relative to the current working
150 directory of the calling process (like
159 The interpretation of
163 except that a relative pathname is interpreted relative
164 to the directory referred to by the file descriptor
169 for an explanation of the need for
180 argument is equivalent to
185 argument is a bit mask consisting of zero or more of the following flags:
200 Both pathnames must exist
201 but may be of different types (e.g., one could be a non-empty directory
202 and the other a symbolic link).
204 On success, zero is returned.
205 On error, \-1 is returned, and
207 is set appropriately.
211 Write permission is denied for the directory containing
215 or, search permission is denied for one of the directories
216 in the path prefix of
222 is a directory and does not allow write permission (needed to update
227 .BR path_resolution (7).)
230 The rename fails because
231 .IR oldpath " or " newpath
232 is a directory that is in use by some process (perhaps as
233 current working directory, or as root directory, or because
234 it was open for reading) or is in use by the system
235 (for example as mount point), while the system considers
237 (Note that there is no requirement to return
240 cases\(emthere is nothing wrong with doing the rename anyway\(embut
241 it is allowed to return
243 if the system cannot otherwise
244 handle such situations.)
247 The user's quota of disk blocks on the filesystem has been exhausted.
250 .IR oldpath " or " newpath " points outside your accessible address space."
253 The new pathname contained a path prefix of the old, or, more generally,
254 an attempt was made to make a directory a subdirectory of itself.
258 is an existing directory, but
263 Too many symbolic links were encountered in resolving
264 .IR oldpath " or " newpath .
268 already has the maximum number of links to it, or
269 it was a directory and the directory containing
271 has the maximum number of links.
274 .IR oldpath " or " newpath " was too long."
280 or, a directory component in
290 Insufficient kernel memory was available.
293 The device containing the file has no room for the new directory
297 A component used as a directory in
298 .IR oldpath " or " newpath
299 is not, in fact, a directory.
304 exists but is not a directory.
306 .BR ENOTEMPTY " or " EEXIST
308 is a nonempty directory, that is, contains entries other than "." and "..".
310 .BR EPERM " or " EACCES
311 The directory containing
315 set and the process's effective user ID is neither
316 the user ID of the file to be deleted nor that of the directory
317 containing it, and the process is not privileged
318 (Linux: does not have the
323 is an existing file and the directory containing it has the sticky bit set
324 and the process's effective user ID is neither the user ID of the file
325 to be replaced nor that of the directory containing it,
326 and the process is not privileged
327 (Linux: does not have the
330 or the filesystem containing
332 does not support renaming of the type requested.
335 The file is on a read-only filesystem.
338 .IR oldpath " and " newpath
339 are not on the same mounted filesystem.
340 (Linux permits a filesystem to be mounted at multiple points, but
342 does not work across different mount points,
343 even if the same filesystem is mounted on both.)
345 The following additional errors can occur for
354 is not a valid file descriptor.
360 is a file descriptor referring to a file other than a directory;
366 The following additional errors can occur for
378 An invalid flag was specified in
387 The filesystem does not support one of the flags in
399 was added to Linux in kernel 2.6.16;
400 library support was added to glibc in version 2.4.
403 was added to Linux in kernel 3.15.
404 .\" FIXME . glibc support is pending.
407 4.3BSD, C89, C99, POSIX.1-2001, POSIX.1-2008.
416 On older kernels where
418 is unavailable, the glibc wrapper function falls back to the use of
424 are relative pathnames,
425 glibc constructs pathnames based on the symbolic links in
427 that correspond to the
433 On NFS filesystems, you can not assume that if the operation
434 failed, the file was not renamed.
435 If the server does the rename operation
436 and then crashes, the retransmitted RPC which will be processed when the
437 server is up again causes a failure.
438 The application is expected to
442 for a similar problem.
449 .BR path_resolution (7),
452 This page is part of release 3.79 of the Linux
455 A description of the project,
456 information about reporting bugs,
457 and the latest version of this page,
459 \%http://www.kernel.org/doc/man\-pages/.