1 .\" Copyright (c) 1983, 1991, 1993
2 .\" The Regents of the University of California. All rights reserved.
4 .\" Redistribution and use in source and binary forms, with or without
5 .\" modification, are permitted provided that the following conditions
7 .\" 1. Redistributions of source code must retain the above copyright
8 .\" notice, this list of conditions and the following disclaimer.
9 .\" 2. Redistributions in binary form must reproduce the above copyright
10 .\" notice, this list of conditions and the following disclaimer in the
11 .\" documentation and/or other materials provided with the distribution.
12 .\" 3. Neither the name of the University nor the names of its contributors
13 .\" may be used to endorse or promote products derived from this software
14 .\" without specific prior written permission.
16 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
17 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
20 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 .\" @(#)rename.2 8.1 (Berkeley) 6/4/93
36 .Nd change the name of a file
42 .Fn rename "const char *from" "const char *to"
44 .Fn renameat "int fromfd" "const char *from" "int tofd" "const char *to"
55 exists, it is first removed.
60 must be of the same type (that is, both directories or both
61 non-directories), and must reside on the same file system.
68 already exists, an instance of
70 will always exist, even if the system should crash in
71 the middle of the operation.
73 If the final component of
76 the symbolic link is renamed,
77 not the file or directory to which it points.
83 resolve to the same directory entry, or to different directory
84 entries for the same existing file,
86 returns success without taking any further action.
90 system call is equivalent to
92 except in the case where either
96 specifies a relative path.
99 is a relative path, the file to be renamed is located
100 relative to the directory associated with the file descriptor
102 instead of the current working directory.
105 is a relative path, the same happens only relative to the directory associated
110 is passed the special value
116 parameter, the current working directory is used in the determination
117 of the file for the respective path parameter.
119 .\"The system can deadlock if a loop in the file system graph is present.
120 .\"This loop takes the form of an entry in directory
124 .\"being a hard link to directory
134 .\"When such a loop exists and two separate processes attempt to
136 .\".Ql rename a/foo b/bar
138 .\".Ql rename b/bar a/foo ,
140 .\"the system may deadlock attempting to lock
141 .\"both directories for modification.
142 .\"Hard links to directories should be
143 .\"replaced by symbolic links by the system administrator.
150 will fail and neither of the argument files will be
153 .It Bq Er ENAMETOOLONG
154 A component of either pathname exceeded 255 characters,
155 or the entire length of either path name exceeded 1023 characters.
164 A component of either path prefix denies search permission.
166 The requested link requires writing in a directory with a mode
167 that denies write permission.
169 The directory pointed at by the
171 argument denies write permission, and the operation would move
172 it to another parent directory.
174 The file pointed at by the
176 argument has its immutable, undeletable or append-only flag set, see the
178 manual page for more information.
180 The parent directory of the file pointed at by the
182 argument has its immutable or append-only flag set.
184 The parent directory of the file pointed at by the
186 argument has its immutable flag set.
188 The directory containing
191 and neither the containing directory nor
193 are owned by the effective user ID.
195 The file pointed at by the
199 the directory containing
202 and neither the containing directory nor
204 are owned by the effective user ID.
206 Too many symbolic links were encountered in translating either pathname.
208 A component of either path prefix is not a directory.
226 and the file named by
228 are on different logical devices (file systems).
230 code will not be returned if the implementation permits cross-device
233 The directory in which the entry for the new name is being placed
234 cannot be extended because there is no space left on the file
235 system containing the directory.
237 The directory in which the entry for the new name
238 is being placed cannot be extended because the
239 user's quota of disk blocks on the file system
240 containing the directory has been exhausted.
242 An I/O error occurred while making or updating a directory entry.
244 Corrupted data was detected while reading from the file system.
246 The requested link requires writing in a directory on a read-only file
250 points outside the process's allocated address space.
255 is a parent directory of
257 or an attempt is made to rename
265 is a directory and is not empty.
268 was called and the process is in capability mode.
271 In addition to the errors returned by the
280 argument does not specify an absolute path and the
284 nor a valid file descriptor open for searching, or the
286 argument does not specify an absolute path and the
290 nor a valid file descriptor open for searching.
294 argument is not an absolute path and
298 nor a file descriptor associated with a directory, or the
300 argument is not an absolute path and
304 nor a file descriptor associated with a directory.
307 is specified and the process is in capability mode.
308 .It Bq Er ENOTCAPABLE
310 is an absolute path or contained a ".." component leading to a directory
311 outside of the directory hierarchy specified by
315 .It Bq Er ENOTCAPABLE
318 file descriptor lacks the
319 .Dv CAP_RENAMEAT_SOURCE
322 file descriptor lacks the
323 .Dv CAP_RENAMEAT_TARGET
333 system call is expected to conform to
337 system call follows The Open Group Extended API Set 2 specification.
341 system call appeared in