Change ownership of file during copy Change ownership of file during copy unix unix

Change ownership of file during copy


As stated here: https://unix.stackexchange.com/questions/124855/move-files-and-change-ownership-at-the-sametime

Use rsync(1):

rsync \  --remove-source-files \  --chown=wanteduser:wantedgroup \    /home/oldfolder /home/newfolder


Not a direct answer to your question, but if you've got GNU cpio available, you can use it (in copy-pass mode) to copy files while changing ownership. eg.

echo 'some_file_name' | cpio -p --owner someuser:somegroup destination_directory


Not easily. You could perhaps run the cp command as the user you want to own the new file, or copy it sideways to a temporary location, chown it then copy it to where it wants to get, but cp itself lacks chown.