3

Let's suppose we have to users: alice and bob.

Now Bob wants to move Alice's ~/Documents directory into his home folder.

What's the best workflow to do that, updating the permissions (from Alice to Bob)?

That means that all the rights Alice has on the /home/alice/Documents/ (directories and files, recursively) to be added to Bob /home/bob/Documents/ (directories and files, recursively), and Alice's rights will be removed from /home/bob/Documents.

2
  • Can you update your question with your interpretation of what are correct permissions? You only talk about ownership in the body of your post.
    – Anthon
    Commented Jan 18, 2015 at 19:07
  • @Anthon I just want to migrate Alice's files to Bob. So, probably only the ownership is the issue. Commented Jan 18, 2015 at 19:40

4 Answers 4

7

If you change the file owner using chown, the permissions for alice would be transferred to bob. So here's the flow:

sudo mv ~bob/Documents ~bob/Documents.orig
sudo mv ~alice/Documents/ ~bob/Documents
sudo chown -PR bob ~bob/Documents

Edit:

In case you want to overwrite the group as well, use

sudo chown -PR bob:bob ~bob/Documents

Or:

sudo chown -PR bob: ~bob/Documents

to use bob's primary group.

However, beware that this could be problematic in case ~alice/Documents had non-default group permissions. In that case it might be better to use something like

sudo find ~bob/Documents -group alice -exec chown -h bob: {} +

If ACLs are in use, you may want to check those as well.

0
5

As Bob:

mv ~bob/Documents ~bob/Documents.orig
cp --remove-destination --no-preserve=ownership -r ~alice/Documents/ ~bob/
sudo rm -fr ~alice/Documents/
5
  • I accepted the other answer, but this looks good too. I voted it and other answers posted by you. :-) Thanks! Commented Jan 18, 2015 at 19:41
  • @Costas: Is there an advantage of using cp vs mv ? The latter only adjust pointers to the filesystem and is much faster if both home folders are on the same filesystem. Or did I miss something ?
    – Karolos
    Commented Jan 18, 2015 at 20:50
  • @Karolos Yes, you are right. But the main advantage of cp have much more options. Thus if we told about files on same filesystem you can use option -l(--link) to make just hard-links instead of copying.
    – Costas
    Commented Jan 18, 2015 at 21:06
  • @Costas I see; good point about the options, and -l is a good option to provide indeed.
    – Karolos
    Commented Jan 18, 2015 at 21:08
  • @Karolos Another point would be that I probably want to delete Alice's documents after one week. :-) So, I used cp instead of mv. Commented Jan 19, 2015 at 5:43
2
cp -avv /home/alice/Documents/ /home/bob/newDocuments/ && 
  chown -Rvv bob:bob /home/bob/newDocuments/
1
  • +1 for considering the group as well (:bob)
    – sourcejedi
    Commented Jan 18, 2015 at 20:45
1

If bob has no permission to read alice's home folder you should do some operations as super user (if Bob has no already that power) I personally will use something like this:

sudo rsync -a --progress /home/alice/Documents/ /home/bob/Documents/
sudo chown -Rv bob:bob_group /home/bob/Documents
sudo rm -rv /home/alice/Documents
  • rsync is very versatile you may chose what files you want to skip or sync an already existing folder or copy from a remote host and more other options. I this example "-a" stands for archive. It implies more rsync options like -r and -p which stands for recursive and preserve permission. It include also -o (preserve owner) and -g (preserve group) and you can tweak this options as you prefer. So at the end of execution of this command you will have a clone an Alice's Documents folder in Bob's home folder.

  • chown will change owner and owner group of new folder

  • rm, will remove original folder if you want that.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .