Seth Woolley's Man Viewer

Manual for rename - man 2 rename

([section] manual, -k keyword, -K [section] search, -f whatis)
man plain no title

RENAME(2)                  Linux Programmer's Manual                 RENAME(2)



NAME
       rename(1,2,n) - change the name or location of a file(1,n)

SYNOPSIS
       #include <stdio.h>

       int rename(1,2,n)(const char *oldpath, const char *newpath);

DESCRIPTION
       rename(1,2,n) renames a file(1,n), moving it between directories if(3,n) required.

       Any  other  hard links to the file(1,n) (as created using link(1,2)(2)) are unaf-
       fected.

       If newpath already exists it will be atomically replaced (subject to  a
       few  conditions - see ERRORS below), so that there is no point at which
       another process attempting to access(2,5) newpath will find it missing.

       If newpath exists but the operation fails for some reason rename(1,2,n)  guar-
       antees to leave an instance of newpath in(1,8) place.

       However, when overwriting there will probably be a window in(1,8) which both
       oldpath and newpath refer to the file(1,n) being renamed.

       If oldpath refers to a symbolic link(1,2) the link(1,2) is  renamed;  if(3,n)  newpath
       refers to a symbolic link(1,2) the link(1,2) will be overwritten.

RETURN VALUE
       On  success,  zero is returned.  On error(8,n), -1 is returned, and errno is
       set(7,n,1 builtins) appropriately.

ERRORS
       EACCES Write permission is denied for the directory containing  oldpath
              or  newpath,  or,  search  permission  is  denied for one of the
              directories in(1,8) the path prefix of oldpath or newpath, or oldpath
              is  a  directory  and does not allow write(1,2) permission (needed to
              update(7,n) the ..  entry).  (See also path_resolution(2).)

       EBUSY  The rename(1,2,n) fails because oldpath or newpath is a directory  that
              is in(1,8) use by some process (perhaps as current working directory,
              or as root directory, or because it was open(2,3,n) for reading) or  is
              in(1,8)  use  by  the  system (for example as mount(2,8) point), while the
              system considers this an error.  (Note that there is no require-
              ment to return EBUSY in(1,8) such cases - there is nothing wrong with
              doing the rename(1,2,n) anyway - but it is allowed to return  EBUSY  if(3,n)
              the system cannot otherwise handle such situations.)

       EFAULT oldpath or newpath points outside your accessible address space.

       EINVAL The new pathname contained a path prefix of the  old,  or,  more
              generally,  an  attempt was made to make a directory a subdirec-
              tory of itself.

       EISDIR newpath is an existing directory, but oldpath is  not  a  direc-
              tory.

       ELOOP  Too many symbolic links were encountered in(1,8) resolving oldpath or
              newpath.

       EMLINK oldpath already has the maximum number of links to it, or it was
              a directory and the directory containing newpath has the maximum
              number of links.

       ENAMETOOLONG
              oldpath or newpath was too long.

       ENOENT A directory component in(1,8) oldpath  or  newpath does not exist  or
              is a dangling symbolic link.

       ENOMEM Insufficient kernel memory was available.

       ENOSPC The device containing the file(1,n) has no room for the new directory
              entry.

       ENOTDIR
              A component used as a directory in(1,8) oldpath or newpath is not, in(1,8)
              fact,  a  directory.   Or,  oldpath  is a directory, and newpath
              exists but is not a directory.

       ENOTEMPTY or EEXIST
              newpath is a non-empty directory, i.e., contains  entries  other
              than "." and "..".

       EPERM or EACCES
              The  directory  containing  oldpath has the sticky bit (S_ISVTX)
              set(7,n,1 builtins) and the process's effective user ID is neither the  user  ID
              of  the  file(1,n) to be deleted nor that of the directory containing
              it, and the process is not privileged (Linux: does not have  the
              CAP_FOWNER  capability);  or newpath is an existing file(1,n) and the
              directory containing it has the sticky bit set(7,n,1 builtins) and the process's
              effective  user  ID  is  neither  the  user ID of the file(1,n) to be
              replaced nor that  of  the  directory  containing  it,  and  the
              process  is  not privileged (Linux: does not have the CAP_FOWNER
              capability); or the filesystem containing pathname does not sup-
              port renaming of the type requested.

       EROFS  The file(1,n) is on a read-only filesystem.

       EXDEV  oldpath and newpath are not on the same filesystem.

CONFORMING TO
       POSIX, 4.3BSD, ANSI C

BUGS
       On NFS filesystems, you can not assume that if(3,n) the operation failed the
       file(1,n) was not renamed.  If the server does the rename(1,2,n) operation and then
       crashes,  the retransmitted RPC which will be processed when the server
       is up again causes a failure.  The application is expected to deal with
       this.  See link(1,2)(2) for a similar problem.

SEE ALSO
       mv(1), chmod(1,2)(2), link(1,2)(2), path_resolution(2), symlink(2), unlink(1,2)(2)



Linux 2.0                         1998-06-04                         RENAME(2)

References for this manual (incoming links)