When moving or copying files as root I often want to set the ownership for those files based on the owner of the directory I am moving the files to.
Before I go off and write a script that parses the rsync output for all the files that were copied over and then goes through those setting chown on each file, is there a better/existing way to do this?
As an example, say I need to copy/move/sync the folder tmp/ftp/new-assests/
to ~user1/tmp/
and to ~user2/html-stuff/
the originals are owned by the user _www and I want the target files and the folder containing them and any other folders to be owned by user1
and user2
, respectively and the target directories have existing files in them.
Yes, the users could copy the fils themselves if they had read access to that folder, but that is irrelevant in this case. Let’s assume these are all nologin users and they do not have access to the source file, if that helps.