Linux Commands#File, Directory
NAME cp - copy files and directories -f, --force if an existing destination file cannot be opened, remove it and try again (this option is ignored when the -n option is also used) -i, --interactive prompt before overwrite (overrides a previous -n option) -p same as --preserve=mode,ownership,timestamps -R, -r, --recursive copy directories recursively
$ sudo touch /tmp/root.txt $ sudo -u user touch /tmp/user.txt $ su - user $ cp /tmp/root.txt /tmp/user.txt $ echo "aaa" > /tmp/user.txt $ sudo cp /tmp/user.txt /tmp/root.txt user.txt : owner is user root.txt : owner is root
$ sudo -u user1 touch /tmp/user1.txt $ sudo su - user2 $ echo "aaa" > /tmp/user2.txt $ sudo -u user1 cp /tmp/user2.txt /tmp/user1.txt user2.txt : owner is user2 user1.txt : owner is user1