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.11—128
xnu-1504.15.3—128
xnu-1504.3.12—128
xnu-1504.7.4—128
xnu-1504.9.17—128
xnu-1504.9.26—128
xnu-1504.9.37—128

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