]> git.ipfire.org Git - thirdparty/man-pages.git/blame - man2/rename.2
ffix
[thirdparty/man-pages.git] / man2 / rename.2
CommitLineData
fea681da
MK
1.\" Hey Emacs! This file is -*- nroff -*- source.
2.\"
3.\" This manpage is Copyright (C) 1992 Drew Eckhardt;
4.\" 1993 Michael Haardt;
5.\" 1993,1995 Ian Jackson.
6.\"
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.
10.\"
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.
15.\"
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
22.\" professionally.
23.\"
24.\" Formatted or processed versions of this manual, if unaccompanied by
25.\" the source, must acknowledge the copyright and authors of this work.
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>
fea681da
MK
30.\"
31.TH RENAME 2 1998-06-04 "Linux 2.0" "Linux Programmer's Manual"
32.SH NAME
33rename \- change the name or location of a file
34.SH SYNOPSIS
35.B #include <stdio.h>
36.sp
37.BI "int rename(const char *" oldpath ", const char *" newpath );
38.SH DESCRIPTION
e511ffb6 39.BR rename ()
fea681da
MK
40renames a file, moving it between directories if required.
41
42Any other hard links to the file (as created using
43.BR link (2))
44are unaffected.
45
46If
47.I newpath
48already exists it will be atomically replaced (subject to
e9496f74 49a few conditions; see ERRORS below), so that there is
fea681da
MK
50no point at which another process attempting to access
51.I newpath
52will find it missing.
53
54If
55.I newpath
56exists but the operation fails for some reason
e511ffb6 57.BR rename ()
fea681da
MK
58guarantees to leave an instance of
59.I newpath
60in place.
61
62However, when overwriting there will probably be a window in which
63both
64.I oldpath
65and
66.I newpath
67refer to the file being renamed.
68
69If
70.I oldpath
71refers to a symbolic link the link is renamed; if
72.I newpath
73refers to a symbolic link the link will be overwritten.
74.SH "RETURN VALUE"
75On success, zero is returned. On error, \-1 is returned, and
76.I errno
77is set appropriately.
78.SH ERRORS
79.TP
80.B EACCES
81Write permission is denied for the directory containing
82.I oldpath
83or
84.IR newpath ,
85or, search permission is denied for one of the directories
86in the path prefix of
87.I oldpath
88or
89.IR newpath ,
90or
91.I oldpath
92is a directory and does not allow write permission (needed to update
93the
836f07c1 94.I ..
fea681da
MK
95entry).
96(See also
97.BR path_resolution (2).)
98.TP
99.B EBUSY
100The rename fails because
101.IR oldpath " or " newpath
102is a directory that is in use by some process (perhaps as
103current working directory, or as root directory, or because
104it was open for reading) or is in use by the system
105(for example as mount point), while the system considers
106this an error.
107(Note that there is no requirement to return EBUSY in such
e9496f74 108cases \(em there is nothing wrong with doing the rename anyway \(em
fea681da
MK
109but it is allowed to return EBUSY if the system cannot otherwise
110handle such situations.)
111.TP
112.B EFAULT
113.IR oldpath " or " newpath " points outside your accessible address space."
114.TP
115.B EINVAL
116The new pathname contained a path prefix of the old, or, more generally,
117an attempt was made to make a directory a subdirectory of itself.
118.TP
119.B EISDIR
120.I newpath
121is an existing directory, but
122.I oldpath
123is not a directory.
124.TP
125.B ELOOP
126Too many symbolic links were encountered in resolving
127.IR oldpath " or " newpath .
128.TP
129.B EMLINK
130.I oldpath
131already has the maximum number of links to it, or
132it was a directory and the directory containing
133.I newpath
134has the maximum number of links.
135.TP
136.B ENAMETOOLONG
137.IR oldpath " or " newpath " was too long."
138.TP
139.B ENOENT
140A directory component in
141.I oldpath " or " newpath
142does not exist or is a dangling symbolic link.
143.TP
144.B ENOMEM
145Insufficient kernel memory was available.
146.TP
147.B ENOSPC
148The device containing the file has no room for the new directory
149entry.
150.TP
151.B ENOTDIR
152A component used as a directory in
153.IR oldpath " or " newpath
154is not, in fact, a directory.
155Or,
156.I oldpath
157is a directory, and
158.I newpath
159exists but is not a directory.
160.TP
161.BR ENOTEMPTY " or " EEXIST
162.IR newpath
163is a non-empty directory, i.e., contains entries other than "." and "..".
164.TP
165.BR EPERM " or " EACCES
166The directory containing
167.I oldpath
168has the sticky bit
169.RB ( S_ISVTX )
170set and the process's effective user ID is neither
171the user ID of the file to be deleted nor that of the directory
172containing it, and the process is not privileged
173(Linux: does not have the
174.B CAP_FOWNER
175capability);
176or
177.I newpath
178is an existing file and the directory containing it has the sticky bit set
179and the process's effective user ID is neither the user ID of the file
180to be replaced nor that of the directory containing it,
181and the process is not privileged
182(Linux: does not have the
183.B CAP_FOWNER
184capability);
185or the filesystem containing
186.IR pathname
187does not support renaming of the type requested.
188.TP
189.B EROFS
190The file is on a read-only filesystem.
191.TP
192.B EXDEV
193.IR oldpath " and " newpath
2d5d4b0d
MK
194are not on the same mounted filesystem.
195(Linux permits a filesystem to be mounted at multiple points, but
196.BR rename (2)
197does not work across different mount points,
198even if the same filesystem is mounted on both.)
fea681da 199.SH "CONFORMING TO"
97c1eac8 2004.3BSD, C89, POSIX.1-2001.
fea681da
MK
201.SH BUGS
202On NFS filesystems, you can not assume that if the operation
203failed the file was not renamed. If the server does the rename operation
204and then crashes, the retransmitted RPC which will be processed when the
205server is up again causes a failure. The application is expected to
206deal with this. See
207.BR link (2)
208for a similar problem.
209.SH "SEE ALSO"
210.BR mv (1),
211.BR chmod (2),
212.BR link (2),
213.BR path_resolution (2),
f5958902 214.BR renameat (2),
fea681da
MK
215.BR symlink (2),
216.BR unlink (2)