]>
Commit | Line | Data |
---|---|---|
fea681da | 1 | .\" This manpage is Copyright (C) 1992 Drew Eckhardt; |
ac56b6a8 MK |
2 | .\" and Copyright (C) 1993 Michael Haardt; |
3 | .\" and Copyright (C) 1993,1995 Ian Jackson. | |
fea681da | 4 | .\" |
93015253 | 5 | .\" %%%LICENSE_START(VERBATIM) |
fea681da MK |
6 | .\" Permission is granted to make and distribute verbatim copies of this |
7 | .\" manual provided the copyright notice and this permission notice are | |
8 | .\" preserved on all copies. | |
9 | .\" | |
10 | .\" Permission is granted to copy and distribute modified versions of this | |
11 | .\" manual under the conditions for verbatim copying, provided that the | |
12 | .\" entire resulting derived work is distributed under the terms of a | |
13 | .\" permission notice identical to this one. | |
c13182ef | 14 | .\" |
fea681da MK |
15 | .\" Since the Linux kernel and libraries are constantly changing, this |
16 | .\" manual page may be incorrect or out-of-date. The author(s) assume no | |
17 | .\" responsibility for errors or omissions, or for damages resulting from | |
18 | .\" the use of the information contained herein. The author(s) may not | |
19 | .\" have taken the same level of care in the production of this manual, | |
20 | .\" which is licensed free of charge, as they might when working | |
21 | .\" professionally. | |
c13182ef | 22 | .\" |
fea681da MK |
23 | .\" Formatted or processed versions of this manual, if unaccompanied by |
24 | .\" the source, must acknowledge the copyright and authors of this work. | |
4b72fb64 | 25 | .\" %%%LICENSE_END |
fea681da MK |
26 | .\" |
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> | |
2d5d4b0d | 29 | .\" Modified Thu Mar 3 09:49:35 2005 by Michael Haardt <michael@moria.de> |
f6a4055f | 30 | .\" 2007-03-25, mtk, added various text to DESCRIPTION. |
fea681da | 31 | .\" |
3fc441b2 | 32 | .TH RENAME 2 2013-01-27 "Linux" "Linux Programmer's Manual" |
fea681da MK |
33 | .SH NAME |
34 | rename \- change the name or location of a file | |
35 | .SH SYNOPSIS | |
36 | .B #include <stdio.h> | |
37 | .sp | |
38 | .BI "int rename(const char *" oldpath ", const char *" newpath ); | |
39 | .SH DESCRIPTION | |
e511ffb6 | 40 | .BR rename () |
fea681da | 41 | renames a file, moving it between directories if required. |
fea681da MK |
42 | Any other hard links to the file (as created using |
43 | .BR link (2)) | |
44 | are unaffected. | |
f6a4055f MK |
45 | Open file descriptors for |
46 | .I oldpath | |
47 | are also unaffected. | |
fea681da MK |
48 | |
49 | If | |
50 | .I newpath | |
51 | already exists it will be atomically replaced (subject to | |
e9496f74 | 52 | a few conditions; see ERRORS below), so that there is |
fea681da MK |
53 | no point at which another process attempting to access |
54 | .I newpath | |
55 | will find it missing. | |
56 | ||
f6a4055f MK |
57 | If |
58 | .I oldpath | |
59 | and | |
60 | .I newpath | |
61 | are existing hard links referring to the same file, then | |
62 | .BR rename () | |
63 | does nothing, and returns a success status. | |
64 | ||
fea681da MK |
65 | If |
66 | .I newpath | |
67 | exists but the operation fails for some reason | |
e511ffb6 | 68 | .BR rename () |
fea681da MK |
69 | guarantees to leave an instance of |
70 | .I newpath | |
71 | in place. | |
72 | ||
f6a4055f MK |
73 | .I oldpath |
74 | can specify a directory. | |
c13182ef | 75 | In this case, |
f6a4055f MK |
76 | .I newpath |
77 | must either not exist, or it must specify an empty directory. | |
78 | ||
fea681da MK |
79 | However, when overwriting there will probably be a window in which |
80 | both | |
81 | .I oldpath | |
82 | and | |
83 | .I newpath | |
84 | refer to the file being renamed. | |
85 | ||
86 | If | |
87 | .I oldpath | |
88 | refers to a symbolic link the link is renamed; if | |
89 | .I newpath | |
90 | refers to a symbolic link the link will be overwritten. | |
47297adb | 91 | .SH RETURN VALUE |
c13182ef MK |
92 | On success, zero is returned. |
93 | On error, \-1 is returned, and | |
fea681da MK |
94 | .I errno |
95 | is set appropriately. | |
96 | .SH ERRORS | |
97 | .TP | |
98 | .B EACCES | |
99 | Write permission is denied for the directory containing | |
100 | .I oldpath | |
101 | or | |
102 | .IR newpath , | |
103 | or, search permission is denied for one of the directories | |
104 | in the path prefix of | |
105 | .I oldpath | |
106 | or | |
107 | .IR newpath , | |
108 | or | |
109 | .I oldpath | |
110 | is a directory and does not allow write permission (needed to update | |
111 | the | |
836f07c1 | 112 | .I .. |
fea681da MK |
113 | entry). |
114 | (See also | |
ad7cc990 | 115 | .BR path_resolution (7).) |
fea681da MK |
116 | .TP |
117 | .B EBUSY | |
118 | The rename fails because | |
119 | .IR oldpath " or " newpath | |
120 | is a directory that is in use by some process (perhaps as | |
121 | current working directory, or as root directory, or because | |
122 | it was open for reading) or is in use by the system | |
123 | (for example as mount point), while the system considers | |
124 | this an error. | |
682edefb | 125 | (Note that there is no requirement to return |
0daa9e92 | 126 | .B EBUSY |
682edefb | 127 | in such |
5503c85e MK |
128 | cases\(emthere is nothing wrong with doing the rename anyway\(embut |
129 | it is allowed to return | |
682edefb MK |
130 | .B EBUSY |
131 | if the system cannot otherwise | |
fea681da MK |
132 | handle such situations.) |
133 | .TP | |
a1f01685 MH |
134 | .B EDQUOT |
135 | The user's quota of disk blocks on the file system has been exhausted. | |
136 | .TP | |
fea681da MK |
137 | .B EFAULT |
138 | .IR oldpath " or " newpath " points outside your accessible address space." | |
139 | .TP | |
140 | .B EINVAL | |
141 | The new pathname contained a path prefix of the old, or, more generally, | |
142 | an attempt was made to make a directory a subdirectory of itself. | |
143 | .TP | |
144 | .B EISDIR | |
145 | .I newpath | |
146 | is an existing directory, but | |
147 | .I oldpath | |
148 | is not a directory. | |
149 | .TP | |
150 | .B ELOOP | |
151 | Too many symbolic links were encountered in resolving | |
152 | .IR oldpath " or " newpath . | |
153 | .TP | |
154 | .B EMLINK | |
155 | .I oldpath | |
156 | already has the maximum number of links to it, or | |
157 | it was a directory and the directory containing | |
158 | .I newpath | |
159 | has the maximum number of links. | |
160 | .TP | |
161 | .B ENAMETOOLONG | |
162 | .IR oldpath " or " newpath " was too long." | |
163 | .TP | |
164 | .B ENOENT | |
3d81b967 MK |
165 | The link named by |
166 | .I oldpath | |
167 | does not exist; | |
168 | or, a directory component in | |
169 | .I newpath | |
170 | does not exist; | |
171 | or, | |
172 | .I oldpath | |
173 | or | |
174 | .I newpath | |
175 | is an empty string. | |
fea681da MK |
176 | .TP |
177 | .B ENOMEM | |
178 | Insufficient kernel memory was available. | |
179 | .TP | |
180 | .B ENOSPC | |
181 | The device containing the file has no room for the new directory | |
182 | entry. | |
183 | .TP | |
184 | .B ENOTDIR | |
185 | A component used as a directory in | |
186 | .IR oldpath " or " newpath | |
187 | is not, in fact, a directory. | |
188 | Or, | |
189 | .I oldpath | |
190 | is a directory, and | |
191 | .I newpath | |
192 | exists but is not a directory. | |
193 | .TP | |
194 | .BR ENOTEMPTY " or " EEXIST | |
0daa9e92 | 195 | .I newpath |
aa796481 | 196 | is a nonempty directory, that is, contains entries other than "." and "..". |
fea681da MK |
197 | .TP |
198 | .BR EPERM " or " EACCES | |
199 | The directory containing | |
200 | .I oldpath | |
201 | has the sticky bit | |
202 | .RB ( S_ISVTX ) | |
203 | set and the process's effective user ID is neither | |
204 | the user ID of the file to be deleted nor that of the directory | |
205 | containing it, and the process is not privileged | |
206 | (Linux: does not have the | |
207 | .B CAP_FOWNER | |
208 | capability); | |
209 | or | |
210 | .I newpath | |
211 | is an existing file and the directory containing it has the sticky bit set | |
212 | and the process's effective user ID is neither the user ID of the file | |
213 | to be replaced nor that of the directory containing it, | |
214 | and the process is not privileged | |
215 | (Linux: does not have the | |
216 | .B CAP_FOWNER | |
217 | capability); | |
24d01c53 | 218 | or the file system containing |
0daa9e92 | 219 | .I pathname |
fea681da MK |
220 | does not support renaming of the type requested. |
221 | .TP | |
222 | .B EROFS | |
24d01c53 | 223 | The file is on a read-only file system. |
fea681da MK |
224 | .TP |
225 | .B EXDEV | |
226 | .IR oldpath " and " newpath | |
24d01c53 MK |
227 | are not on the same mounted file system. |
228 | (Linux permits a file system to be mounted at multiple points, but | |
2777b1ca | 229 | .BR rename () |
2d5d4b0d | 230 | does not work across different mount points, |
24d01c53 | 231 | even if the same file system is mounted on both.) |
47297adb | 232 | .SH CONFORMING TO |
1eb85d14 | 233 | 4.3BSD, C89, C99, POSIX.1-2001. |
fea681da | 234 | .SH BUGS |
24d01c53 | 235 | On NFS file systems, you can not assume that if the operation |
c13182ef MK |
236 | failed the file was not renamed. |
237 | If the server does the rename operation | |
fea681da | 238 | and then crashes, the retransmitted RPC which will be processed when the |
c13182ef MK |
239 | server is up again causes a failure. |
240 | The application is expected to | |
241 | deal with this. | |
242 | See | |
fea681da MK |
243 | .BR link (2) |
244 | for a similar problem. | |
47297adb | 245 | .SH SEE ALSO |
fea681da MK |
246 | .BR mv (1), |
247 | .BR chmod (2), | |
248 | .BR link (2), | |
f5958902 | 249 | .BR renameat (2), |
fea681da | 250 | .BR symlink (2), |
ad7cc990 | 251 | .BR unlink (2), |
a9cfde1d | 252 | .BR path_resolution (7), |
ad22ad55 | 253 | .BR symlink (7) |