Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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

share|improve this question
    
-o, --owner preserve owner (super-user only) Are you super? –  frostschutz Apr 9 '13 at 23:19
    
@frostschutz I have updated the OP. –  user815423426 Apr 9 '13 at 23:20
1  
mv may work within the same filesystem, since it stays one and the same file. Other than that, you just don't have permission to create a new file with weird ownership. Compare chown user file. –  frostschutz Apr 9 '13 at 23:21
add comment

1 Answer

up vote 1 down vote accepted

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).

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.