I've got a file owned by a non-root user:
# ls -l example.php
-rw------- 1 foo bar ... example.php
I just applied a patch with a command like
patch -p0 <<-EOF
--- .../example.php.orig 2012-06-20 15:07:13.000000000 +0200
+++ .../example.php 2012-06-20 15:43:05.000000000 +0200
...
EOF
as root and the target file user and group were both changed to root. I couldn't find any reference to this in the man pages.
Is there a way to leave the file ownership as before without using su, sudo, or chown?
suseems unable to specify a group.sudo -u foo patch ...runs fine, but sets the wrong group.sudo -u foo -g bar patch ...returnsSorry, user root is not allowed to execute '/usr/bin/patch' as foo:bar on hostname. This might be because userfoois not a member of groupbar.chownwould mean having to store the permissions before runningpatch, adding another two lines of code.