Re: How does chown(2) works with symlinks?

Linus Torvalds (
Mon, 8 Jul 1996 10:38:31 +0300 (EET DST)

> Which file gets changed when a call to chown(2) is done on a symlink?
> The man page gives the impression that it would follow the symlink and
> change the owner of the file pointed by the symlink. Still, if a used
> chown on a symlink now, it will only change the symlink. Was there a
> change to the way it works?

If you want to change the owner of the file it points to, use:

fd = open(...);

which should always work the way you expect. If you use "chown()" on the
pathname it will change the synlink itself (if you think about it, that is
actually the reasonable behaviour: otherwise you could never change the owner
of the symlink).

I think some older versions of linux actually changed the file that the symlink
pointed to, and it got changed at one point. I could be mistaken, though,