Skip to content
BSD syscall#128

svc · unix #128

rename

Atomically renames a file or directory, possibly replacing an existing target on the same filesystem.

Prototype

int rename(char *from, char *to);

Returns: int

Arguments

NameTypeDirDescription
fromchar-
tochar-

Version history

XNU tagmacOS#
xnu-1456.1.26macOS 10.6 Snow Leopard128
xnu-1486.2.11128
xnu-1504.15.3128
xnu-1504.3.12128
xnu-1504.7.4128
xnu-1504.9.17128
xnu-1504.9.26128
xnu-1504.9.37128

Notes

Cross-filesystem renames return EXDEV; userland tools fall back to copy+unlink. On APFS rename is implemented as a transactional metadata operation and is durable on success. Replacing a non-empty directory fails with ENOTEMPTY.

Detection

ES emits ES_EVENT_TYPE_NOTIFY_RENAME with source and destination paths.

Related APIs

renameatrenamex_nplinkunlinkexchangedata