Is there a combine variant for chmod and chgrp that sets both permissions and groups in one single system call for each file?
Shell Command that Combines chmod and chgrp
2.5k Views Asked by Nordlöw At
2
There are 2 best solutions below
0
On
AFAIK, no.
Furthermore, since the file access mode and owner / group information are set using different syscalls (see man 2 chmod and man 2 chown), I don't think it would be possible to implement such a command ... at least on a mainstream Unix-like system.
(Obviously, one could modify a GNU/Linux kernel to add a combined system call, but then the hypothetical command that used the syscall wouldn't be portable.)
There is no such a variant because the two operations
chmod(2)andchown(2)are implemented by distinct system calls.Getting away with
chmodandchownYou might be looking for such a variant of
chmodandchownbecause of security issues. If this is the case, you can use the following strategy:This way you avoid potential security issues associated to successive calls to
chmodandchownor tochownandchmod.The
install/opentrickThe only system call setting mode flags and ownership information at the same time might be
open(2). So, you could use a process impersonating the target owner opening the file with the appropriate mode. This is probably whatinstalldoes, so if this is an option:installcommand.Doing this will break hard links, however. The solution based on
chownandchmoddoes not have that issue.