Is it true to say (on Windows and UnixLinuxOS X) that renaming a file or directory is just an alias for moving?
e.g.
- Are there any side effects to either which are not present on the other?
- Does ‘rename’ actually ‘move’ move under the hood?
Is there a way I can provedisprove this?
6
Is there a way I can provedisprove this?
No, because
- Different operating systems do things differently.
-
Different kinds of renames/moves can be conceptually different acts:
- Renaming/moving a file within the same directory,
- Renaming/moving a file from one folder/directory to another on the same logical device,
- Renaming/moving a file from one logical device to another, and
- Renaming/moving a file from one physical device to another.
On most common modern systems, renaming/moving a file within the same logical device is a simple matter of deleting the reference to the file object from the original location and adding a reference to the file object in the target location. The contents of the file are not touched.
This is impossible when “moving” across physical devices. The contents of the file to be moved don’t exist on the target device. The contents have to be copied. How moving across logical devices depends on the operating system’s concept of a logical device.
The extra options supported by Win32 MoveFileEx
function provide a good overview and explanation of the similarities and differences between renaming and moving.
When moving files across volumes, a copy (followed by delete) is performed.
From the perspective of an ordinary computer user, when one wants to perform a rename, one would expect the computer to prevent this from overwriting an existing file of the same name.
Whereas copying and moving would offer a choice of cancelling, auto-renaming, or replacing (overwriting).
Note that this is from a user’s perspective, not from a programmer’s perspective. However, the API must support additional flags so that the programmer can implement the user’s expectations.
In summary, due to conventions inherited from the days of MS-DOS, a “rename” is perceived to be less destructive (other than being renamed) than a “move”, even though the distinction no longer has any relevance to the underlying mechanism (the file system) unless the operation spans different file systems.
Unix and Linux had been designed by programmers, for programmers. Therefore the opinions of ordinary computer users had never factored into the design of file system commands, so the distinction does not exist there.
2