In computing, rename refers to the operation of changing the name of a file, directory, or other computing object—such as a variable in a program or a relation in a database—while preserving the object's underlying content, data, and associated metadata. This process updates the reference or identifier used to access the object without modifying its intrinsic properties.
Overview
Renaming can be performed manually by using a shell command such as ren (on Windows and MS-DOS) or mv (on Unix-like systems), or by using batch renaming software that automates the renaming process for multiple files at once. In graphical user interfaces, renaming is typically done by selecting a file and pressing a function key (e.g., F2 on Windows) or by right-clicking and choosing "Rename."
System-Level Implementation
POSIX (Unix-like Systems)
In Unix-like operating systems, the rename operation is standardized by the POSIX specification, which defines the rename() system call. This call takes two parameters: the source path and the destination path. When the source and destination reside on the same file system, the operation is performed atomically—meaning that from the perspective of other processes, the file is seen either with its old name or its new name, never in an intermediate or inconsistent state. If the source and destination are on different mounted file systems, the operation fails with the EXDEV error ("cross-device link"), and a copy-then-delete fallback must be used instead.
The C standard library provides a rename function that performs this action (ISO/IEC 9899:1999, § 7.19.4.2). The POSIX specification extends this behavior.
Windows
In Windows, the foundational command originated with MS-DOS, where the ren (or rename) command allowed users to change filenames within the same directory. The Windows API provides functions such as MoveFile and MoveFileEx for programmatic renaming. The MoveFileEx function supports flags including MOVEFILE_REPLACE_EXISTING (to overwrite an existing destination), MOVEFILE_COPY_ALLOWED (for cross-volume operations), and MOVEFILE_DELAY_UNTIL_REBOOT (to schedule renames for system restart). The C library's rename function on Windows does not implement the POSIX atomic behavior; instead it fails if the destination file already exists.
SQL
In SQL, renaming is performed using the CHANGE or RENAME specification in ALTER TABLE statements, or through database-specific RENAME TABLE commands.
Atomic Rename
A key property of the rename operation in POSIX-compliant systems is atomicity. A successful call to rename is guaranteed to be atomic from the point of view of the current host—another program would only see the file with the old name or the file with the new name, not both or neither. This property is often used during file save operations: new content is written to a temporary file, which is then atomically renamed over the target file, ensuring that the file contents are never lost or left in a partially written state if the operation is interrupted.
Security Considerations
Rename operations can be susceptible to time-of-check-to-time-of-use (TOCTOU) race conditions, where a process checks a file's permissions or existence before renaming it, and an attacker exploits the intervening time window to alter the file. Symlink attacks can also occur when an adversary modifies a symbolic link during a rename window. Secure APIs such as renameat() in Unix-like systems mitigate these risks by operating on file descriptors rather than path strings.
See Also
- Batch renaming
- Ren (command)
- mv (Unix)
- Register renaming (a distinct concept in computer architecture)