1rename(2)                     System Calls Manual                    rename(2)
2
3
4

NAME

6       rename, renameat, renameat2 - change the name or location of a file
7

LIBRARY

9       Standard C library (libc, -lc)
10

SYNOPSIS

12       #include <stdio.h>
13
14       int rename(const char *oldpath, const char *newpath);
15
16       #include <fcntl.h>           /* Definition of AT_* constants */
17       #include <stdio.h>
18
19       int renameat(int olddirfd, const char *oldpath,
20                    int newdirfd, const char *newpath);
21       int renameat2(int olddirfd, const char *oldpath,
22                    int newdirfd, const char *newpath, unsigned int flags);
23
24   Feature Test Macro Requirements for glibc (see feature_test_macros(7)):
25
26       renameat():
27           Since glibc 2.10:
28               _POSIX_C_SOURCE >= 200809L
29           Before glibc 2.10:
30               _ATFILE_SOURCE
31
32       renameat2():
33           _GNU_SOURCE
34

DESCRIPTION

36       rename()  renames  a  file,  moving it between directories if required.
37       Any other hard links to the file (as created using link(2))  are  unaf‐
38       fected.  Open file descriptors for oldpath are also unaffected.
39
40       Various restrictions determine whether or not the rename operation suc‐
41       ceeds: see ERRORS below.
42
43       If newpath already exists, it will  be  atomically  replaced,  so  that
44       there is no point at which another process attempting to access newpath
45       will find it missing.  However, there will  probably  be  a  window  in
46       which both oldpath and newpath refer to the file being renamed.
47
48       If  oldpath  and  newpath are existing hard links referring to the same
49       file, then rename() does nothing, and returns a success status.
50
51       If newpath exists but the operation fails  for  some  reason,  rename()
52       guarantees to leave an instance of newpath in place.
53
54       oldpath can specify a directory.  In this case, newpath must either not
55       exist, or it must specify an empty directory.
56
57       If oldpath refers to a symbolic link, the link is renamed;  if  newpath
58       refers to a symbolic link, the link will be overwritten.
59
60   renameat()
61       The  renameat()  system  call  operates  in exactly the same way as re‐
62       name(), except for the differences described here.
63
64       If the pathname given in oldpath is relative, then  it  is  interpreted
65       relative  to  the directory referred to by the file descriptor olddirfd
66       (rather than relative to the current working directory of  the  calling
67       process, as is done by rename() for a relative pathname).
68
69       If oldpath is relative and olddirfd is the special value AT_FDCWD, then
70       oldpath is interpreted relative to the current working directory of the
71       calling process (like rename()).
72
73       If oldpath is absolute, then olddirfd is ignored.
74
75       The interpretation of newpath is as for oldpath, except that a relative
76       pathname is interpreted relative to the directory referred  to