Permissions – Move File to Another User’s Home Directory Without Sudo

mvpermissionsscp

I have a couple of files that I want to move to another's user home directory. I don't have permissions to write to that user's home directory, but I know his password.

I know how to copy the file using scp (see here). However, if I want to move the file, copying and then removing the original file is inefficient. Is there a way to move the file, without using sudo (I don't know the root's password)?

Best Answer

Subject to certain assumptions that the target user can actually access the file in its original location, the following approach could work:

SRC='/path/to/existing/file'
DST='/path/to/new/file'

su target_user sh -c "ln -f '$SRC' '$DST'" && rm -f "$SRC"

This "moves" the file to the new user's location, but does not change the ownership or permissions.

Related Question