Unable to preserve ownership in a copy but able with a move

filespermissionsrenamersyncusers

I have noticed that I am unable to preserve ownership if I rsync -o files. However, I am when I move them. This is all without admin privileges. What is the rationale of this? Several threads e.g. (1) seem to echo the need for admin privileges

Best Answer

When you move a file within the same filesystem, this detaches the file from its original location and attaches it to the new location. The file data is unchanged, and the file metadata — the inode — is also unchanged. So the file retains its ownership, permissions, times, and any other attribute: only its name and containing directory changes (and also the inode change time (ctime)).

When you copy a file (with rsync or any other utility), this creates a new file with the same contents, belonging to you, with its modification time set to the date the copy was finished. Depending on the copy utility, it may additionally copy some of the file's metadata over from the original, e.g. the owning user with rsync -o.

Moving an inode only requires write permission on the source directory (to detach it) and on the target directory (to reattach it). It doesn't require that you own the file or even can read or write it. On the other hand, you cannot create a file belonging to another user, or give away a file to another user (except for programs running as root). So copying a file as non-root cannot preserve ownership (unless the user doing the copy owned the original file).