3

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

  • 2
    using sudo doesn't require the root p/w, but your own, as long as your user is in the sudoer group. – fduff Feb 19 '15 at 19:46
  • 2
    FYI, a move on the same filesystem is not copy then delete. A move just moves. It's only moves across filesystems that are simulated by copying and deleting. – Gilles 'SO- stop being evil' Feb 19 '15 at 23:31
4

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.

| improve this answer | |
  • 1
    +1 This does link unlink (an implementation of move), as different users. So no write access of source files is needed by receiving user. – ctrl-alt-delor Feb 19 '15 at 23:42
  • I want to move a full directory (along with its contents). I get an error: ln: ‘$SRC’: hard link not allowed for directory – becko Jun 2 '16 at 12:17
  • This answers my original question. I asked about directories here. – becko Jun 2 '16 at 12:20
0

You can su to any user, if you know there password. (for sudo you need to be a sudoer, and know your own password).

So make the files readable and directory writeable(for deletion) by the other user, add files to a shared group, or use access-control-lists (ACLs) setfacl (What are the different ways to set file permissions etc on gnu/linux)

Then su other user Then do the move.


Also look at @roaima 's answer for how to do it without giving write access away to receiving user.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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