I have a script used in different environments. This scripts uses sudo cp
to copy files (sudo otherwise it has no access). But sudo cp
creates the files with the wrong owner. It cannot keep the owner of the source files because these to are the wrong ones. Also the owner of the destination directories are different in the locations where this script is used.
Is there a way to sudo cp
and set the owner/group to the destination directory owner/group?
chown
to set the desired owner to the copied files.