Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

On Linux (Debian, Ubuntu Mint...),
Is there any option command or something that I can use to transfer files to another user without having to do :

sudo mv /home/poney/folderfulloffiles /home/unicorn/
sudo chown -R unicorn:unicorn /home/unicorn/folderfulloffiles
share|improve this question
up vote 23 down vote accepted

Use rsync(1):

rsync \
  --remove-source-files \
  --chown=unicorn:unicorn \
    /home/poney/folderfulloffiles /home/unicorn/
share|improve this answer
Thanks @dawud - this is my daily "stuff I didn't know and can't understand how I missed it" – Jenny D Apr 15 '14 at 10:04
@JennyD you might want to take a look at the usermap and groupmap options as well. – dawud Apr 15 '14 at 10:09
But this doesn't mv it, right? Only copies? Or does it mv it? – mikeserv Apr 15 '14 at 11:00
@mikeserv duly noted, see my edit – dawud Apr 15 '14 at 11:03
Thanks, man. That definitely does do it. – mikeserv Apr 15 '14 at 11:17

Per @Kevin in the comments below, the --file - |pipe syntax is redundant. So I've removed it.

This can also be done with tar:

sudo tar -C${SRC_DIR} --remove-files --group=unicorn --owner=unicorn -c ./* | 
    sudo tar -C${TGT_DIR} -pvx
share|improve this answer
Pretty sure the -f - is implied on both ends. – Kevin Apr 15 '14 at 21:09
@Kevin Not here. Here it's specified. – mikeserv Apr 15 '14 at 21:16
Yes, you specified it, but it's not necessary. Your command works fine without the f - part. – Kevin Apr 15 '14 at 21:31
s=/home/poney/; f=folderfulloffiles; d=/home/unicorn/ 
sudo mv $s$f $d && sudo chown -R unicorn:unicorn $d$f

About the same length as the other answers, and note since they're all using the same library calls under the hood, they're all doing exactly the same thing -- unless, as Gilles notes, this is on the same filesystem and device, in which case mv is really a rename, which makes it more efficient than rsync or tar.

share|improve this answer
It isn't a : instead of a . when dealing with chown ? – Kiwy Apr 15 '14 at 12:54
Hmmm -- interesting. It's that way in the man page, but I've always used a dot. Looks like they took it out of the GNU man page about a decade ago because it's not POSIX portable. Still works though (with the chown from GNU coreutils on linux), but I'll change that above. – goldilocks Apr 15 '14 at 13:03
chown typically takes both : and .. – slm Apr 15 '14 at 13:07
You could do it a little shorter: nu=unicorn h=/home f=folderfulloffiles ; sudo mv $h/poney/$f $h/$nu/$f ; sudo chown -R ${nu}:$nu $_ - though that's hardly the point of your answer, which is good and I've already upvoted. – mikeserv Apr 15 '14 at 13:13
This solution has the advantage that if the source and the destination are on the same filesystem, the file is moved rather than copied and the original erased. – Gilles Apr 15 '14 at 22:22

Your Answer


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.