rename(2) System Calls Manual rename(2) rename, renameat, renameat2 - LIBRARY Standard C library (libc, -lc) #include int rename(const char *oldpath, const char *newpath); #include /* AT_* */ #include int renameat(int olddirfd, const char *oldpath, int newdirfd, const char *newpath); int renameat2(int olddirfd, const char *oldpath, int newdirfd, const char *newpath, unsigned int flags); glibc (. feature_test_macros(7)): renameat(): Since glibc 2.10: _POSIX_C_SOURCE >= 200809L Before glibc 2.10: _ATFILE_SOURCE renameat2(): _GNU_SOURCE rename() , , . ( link(2)), . oldpath . : . newpath , , , newpath, . , oldpath newpath . oldpath newpath , rename() . newpath , , rename() , newpath . oldpath . newpath , . oldpath , ; newpath , , . renameat() renameat() rename(), , . oldpath , , olddirfd ( , rename()). oldpath olddirfd AT_FDCWD, oldpath ( rename()). oldpath , olddirfd . newpath oldpath, , , newdirfd. openat(2) renameat(). renameat2() renameat2() flags. flags , renameat2() renameat(). flags , : RENAME_EXCHANGE oldpath newpath. , (, , ). RENAME_NOREPLACE newpath. , newpath . RENAME_NOREPLACE RENAME_EXCHANGE. RENAME_NOREPLACE ; : o ext4 ( Linux 3.15); o btrfs, tmpfs, and cifs (Linux 3.17); o xfs ( Linux 4.0); o Linux 4.9: ext2, minix, reiserfs, jfs, vfat bpf. RENAME_WHITEOUT ( Linux 3.18) / . RENAME_WHITEOUT <<>> (whiteout object). , . <<>> -- , / . , . , , . , , ( ) , - . , <<>> ( ). . / {0,0} (, / ; , BSD , DT_WHT, , , Linux, CODA XFS, , , Linux 4.19). RENAME_WHITEOUT , (. ., CAP_MKNOD). RENAME_WHITEOUT RENAME_EXCHANGE. RENAME_WHITEOUT requires support from the underlying filesystem. Among the filesystems that support it are tmpfs (since Linux 3.18), ext4 (since Linux 3.18), XFS (since Linux 4.1), f2fs (since Linux 4.2), btrfs (since Linux 4.7), and ubifs (since Linux 4.9). On success, zero is returned. On error, -1 is returned, and errno is set to indicate the error. EACCES , oldpath newpath, , oldpath newpath , oldpath , ( ..); path_resolution(7)). EBUSY The rename fails because oldpath or newpath is a directory that is in use by some process (perhaps as current working directory, or as root directory, or because it was open for reading) or is in use by the system (for example as a mount point), while the system considers this an error. (Note that there is no requirement to return EBUSY in such cases--there is nothing wrong with doing the rename anyway--but it is allowed to return EBUSY if the system cannot otherwise handle such situations.) EDQUOT . EFAULT oldpath newpath . EINVAL , , . EISDIR newpath , oldpath . ELOOP oldpath newpath . EMLINK oldpath , , newpath, . ENAMETOOLONG oldpath newpath. ENOENT , oldpath, ; newpath ; oldpath newpath . ENOMEM . ENOSPC , , . ENOTDIR , oldpath newpath, . oldpath newpath, . ENOTEMPTY EEXIST newpath , , <<.>> <<..>>. EPERM EACCES , oldpath, (S_ISVTX) , , (Linux: CAP_FOWNER); newpath , , , , (Linux: CAP_FOWNER); , oldpath, . EROFS , . EXDEV oldpath newpath (Linux , rename() , ). renameat() renameat2() : EBADF oldpath (newpath) is relative but olddirfd (newdirfd) is not a valid file descriptor. ENOTDIR oldpath olddirfd , , ; newpath newdirfd. renameat2() : EEXIST flags RENAME_NOREPLACE, newpath . EINVAL flags . EINVAL flags , RENAME_NOREPLACE RENAME_EXCHANGE. EINVAL flags , RENAME_WHITEOUT RENAME_EXCHANGE. EINVAL flags. ENOENT flags RENAME_EXCHANGE, newpath . EPERM flags RENAME_WHITEOUT , CAP_MKNOD. rename() C11, POSIX.1-2008. renameat() POSIX.1-2008. renameat2() Linux. rename() 4.3BSD, C89, POSIX.1-2001. renameat() Linux 2.6.16, glibc 2.4. renameat2() Linux 3.15, glibc 2.28. glibc , renameat() , glibc rename(). oldpath newpath , glibc /proc/self/fd, olddirfd newdirfd. NFS , , . , , RPC , . . link(2), . . mv(1), rename(1), chmod(2), link(2), symlink(2), unlink(2), path_resolution(7), symlink(7) aereiae , Azamat Hackimov , Dmitriy S. Seregin , Katrin Kutepova , Lockal , Yuri Kozlov , ; GNU 3 , . . , , . Linux man-pages 6.06 31 2023 . rename(2)