So there's chown which lets you change the owner and group of files and/or directories. But there's also chgrp which only changes the group. Why was chgrp created? Isn't it redundant?
- 1You can refer to the link here for more information. serverfault.com/questions/462174/…Ramesh– Ramesh2014-06-13 16:49:28 +00:00Commented Jun 13, 2014 at 16:49
2 Answers
chown initially couldn't set the group. Later, some implementations added it as chown user.group, some as chown user:group until it was eventually standardised (emphasis mine):
The 4.3 BSD method of specifying both owner and group was included in this volume of POSIX.1-2008 because:
There are cases where the desired end condition could not be achieved using the chgrp and chown (that only changed the user ID) utilities. (If the current owner is not a member of the desired group and the desired owner is not a member of the current group, the chown() function could fail unless both owner and group are changed at the same time.)
Even if they could be changed independently, in cases where both are being changed, there is a 100% performance penalty caused by being forced to invoke both utilities.
Even now:
chown :groupto only change the group is not portable or standard.chown user:to assign the primary group of theuserin the user database is not standard either.
- 2@dayuloli, thanks for the edit, but I didn't include that section of the spec because I don't understand itStéphane Chazelas– Stéphane Chazelas2014-06-14 08:09:28 +00:00Commented Jun 14, 2014 at 8:09
- Good question! Upvoted!dayuloli– dayuloli2014-06-14 11:29:37 +00:00Commented Jun 14, 2014 at 11:29
- Nice to see that :group ans user: have been mentioned as non-standard. Many people here only check what their local vendor does and this is not helpful in a generic UNIX portal.schily– schily2018-07-18 12:13:25 +00:00Commented Jul 18, 2018 at 12:13
Root privileges are required when changing the user-owner* of a file.
A regular user can change the group-owner of a file to another group that he/she is a member of.
Maybe from this privilege perspective it made sense to keep them separate, especially in the pre-sudo era. Like chown could have been made setuid with a group of 'admin', allowing members of the 'admin' group to change the user-owner of files.
* I use "user-owner" and "group-owner" and "others" for consistency with ugo. Confusing "o" for "owner" is a common mistake.