Why the modern chown command uses a colon to separate the user and group
In the beginning, all chown(1)
did was change the owner of a file;
if you wanted to change a file's group too, you had to use chgrp(1)
as well. This is actually more unusual than I realized before I started
to write this entry, because even in V7 Unix the chown(2)
system call
itself could change both user and group, per the V7 chown(2)
manpage.
Restricting chown(1)
to only changing the owner did make the command
itself
pretty simple, though.
By the time of 4.1c BSD, chown(1)
had become chown(8)
,
because, per the manual page:
Only the super-user can change owner,
in order to simplify as yet unimplemented accounting procedures.
(The System V line of Unixes would retain an unrestricted chown(2)
system call for some time and thus I believe they kept the chown
command in section 1, for general commands anyone could use.)
In 4.3 BSD, someone decided that chown(8)
might as well let you change
the group at the same time, to match the system call. As the manual page
covers, they used this syntax:
/etc/chown [ -f -R ] owner[.group] file ...
That is, to chown a file to user cks
, group staff
, you did
'chown cks.staff file
'.
This augmented version of the chown
command was picked up by various
Unixes that descended from 4.x BSD, although not immediately (like many
things from 4.3 BSD, it took a while to propagate around). Sometimes
this was the primary version of chown
, found in /usr/bin
or the
like; sometimes this was a compatibility version, in /usr/ucb
(Solaris
through fairly late, for example). Depending on how you set up your
$PATH
on such systems, you could wind up using this version of chown
and thus get used to having 'user:group' rejected as an error.
Then, when it came time for POSIX to standardize this, someone woke
up and created the modern syntax for changing both owner and group
at once. As seen in the Single Unix Specification for chown
,
this is 'chown owner[:group] file
', ie the separator is now a
colon. Since POSIX and the SUS normally standardized existing
practice (where it actually existed), you might wonder why they
changed it. The answer is simple: a colon is not a valid character
in a login, while a dot is.
Sure, dots are unusual in Unix logins in most places, but they're
legal and they do show up in some environments (and they're legal
in group names as well). Colons are outright illegal unless you
like explosions, fundamentally because they're the field separator
character in /etc/passwd
and /etc/group
. The SUS manpage
actually has an explicit discussion of this in the RATIONALE section,
although it doesn't tell you what it means by 'historical
implementations'.
(The SUS manpage also discusses a scenario where using chown
and
chgrp
separately isn't sufficient, and you have to make the change
in a single chown()
system call.)
PS: Since I think I ran into this dot-versus-colon issue on our
old Solaris 10 fileservers, I
probably had /usr/ucb
before /usr/bin
in my $PATH
there. I
generally prefer UCB versions of things to the stock Solaris versions,
but in this case it tripped me up.
PPS: It turns out the GNU chown accepts the dot form as well provided that it's unambiguous, although this is covered only in the chown info file, and is not mentioned in the normal manpage.
|
|