1 .\" Hey Emacs! This file is -*- nroff -*- source.
3 .\" This manpage is Copyright (C) 1992 Drew Eckhardt;
4 .\" 1993 Michael Haardt;
5 .\" 1993,1995 Ian Jackson.
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.
27 .\" Modified Sat Jul 24 00:35:52 1993 by Rik Faith <faith@cs.unc.edu>
28 .\" Modified Thu Jun 4 12:21:13 1998 by Andries Brouwer <aeb@cwi.nl>
29 .\" Modified Thu Mar 3 09:49:35 2005 by Michael Haardt <michael@moria.de>
31 .TH RENAME 2 1998-06-04 "Linux 2.0" "Linux Programmer's Manual"
33 rename \- change the name or location of a file
37 .BI "int rename(const char *" oldpath ", const char *" newpath );
40 renames a file, moving it between directories if required.
42 Any other hard links to the file (as created using
48 already exists it will be atomically replaced (subject to
49 a few conditions - see ERRORS below), so that there is
50 no point at which another process attempting to access
56 exists but the operation fails for some reason
58 guarantees to leave an instance of
62 However, when overwriting there will probably be a window in which
67 refer to the file being renamed.
71 refers to a symbolic link the link is renamed; if
73 refers to a symbolic link the link will be overwritten.
75 On success, zero is returned. On error, \-1 is returned, and
81 Write permission is denied for the directory containing
85 or, search permission is denied for one of the directories
92 is a directory and does not allow write permission (needed to update
97 .BR path_resolution (2).)
100 The rename fails because
101 .IR oldpath " or " newpath
102 is a directory that is in use by some process (perhaps as
103 current working directory, or as root directory, or because
104 it was open for reading) or is in use by the system
105 (for example as mount point), while the system considers
107 (Note that there is no requirement to return EBUSY in such
108 cases - there is nothing wrong with doing the rename anyway -
109 but it is allowed to return EBUSY if the system cannot otherwise
110 handle such situations.)
113 .IR oldpath " or " newpath " points outside your accessible address space."
116 The new pathname contained a path prefix of the old, or, more generally,
117 an attempt was made to make a directory a subdirectory of itself.
121 is an existing directory, but
126 Too many symbolic links were encountered in resolving
127 .IR oldpath " or " newpath .
131 already has the maximum number of links to it, or
132 it was a directory and the directory containing
134 has the maximum number of links.
137 .IR oldpath " or " newpath " was too long."
140 A directory component in
141 .I oldpath " or " newpath
142 does not exist or is a dangling symbolic link.
145 Insufficient kernel memory was available.
148 The device containing the file has no room for the new directory
152 A component used as a directory in
153 .IR oldpath " or " newpath
154 is not, in fact, a directory.
159 exists but is not a directory.
161 .BR ENOTEMPTY " or " EEXIST
163 is a non-empty directory, i.e., contains entries other than "." and "..".
165 .BR EPERM " or " EACCES
166 The directory containing
170 set and the process's effective user ID is neither
171 the user ID of the file to be deleted nor that of the directory
172 containing it, and the process is not privileged
173 (Linux: does not have the
178 is an existing file and the directory containing it has the sticky bit set
179 and the process's effective user ID is neither the user ID of the file
180 to be replaced nor that of the directory containing it,
181 and the process is not privileged
182 (Linux: does not have the
185 or the filesystem containing
187 does not support renaming of the type requested.
190 The file is on a read-only filesystem.
193 .IR oldpath " and " newpath
194 are not on the same mounted filesystem.
195 (Linux permits a filesystem to be mounted at multiple points, but
197 does not work across different mount points,
198 even if the same filesystem is mounted on both.)
200 POSIX, 4.3BSD, ANSI C
202 On NFS filesystems, you can not assume that if the operation
203 failed the file was not renamed. If the server does the rename operation
204 and then crashes, the retransmitted RPC which will be processed when the
205 server is up again causes a failure. The application is expected to
208 for a similar problem.
213 .BR path_resolution (2),