http://www.perlmonks.org?node_id=168970

v_thunder has asked for the wisdom of the Perl Monks concerning the following question:

I am testing this on HP-UX 11.00 on PA-RISC.

The perl chown command is following links when the last argument is a symbolic link and not a normal file. I'd like to change the ownership of the link itself.

Just for completeness: GNU chown sets the owner:group of the link itself. HP-UX's chown behaves as perl does.

SoPWified - dvergin 2002-05-24

Replies are listed 'Best First'.
Re: How do I change the owner:group of a symlink?
by Marza (Vicar) on May 24, 2002 at 19:58 UTC

    Actually you can't in Perl.

    As Tom Christiansen has said(I don't remember where):

    "Perl doesn't do this. Do you know why many systems don't support the idea? Because it conveys no distict functionality. Modes and owners and times on symbolic links have no meaning. So why bother? And it's very non-portable."

    Now as to making a system call. Did you use the "-h" option? I did and it did change the link's ownership without changing the file.

      Oh, bummer. I know it doesn't really matter, but I just need this group of to be owned by bin:bin. Just, uh, because :)

      And you are absolutely right about the -h option. I don't know how I missed it, it's the first option on HP-UX's chown(1) manpage!

      Thanks a bunch,
      -Dan

Re: How do I change the owner:group of a symlink?
by Anonymous Monk on Jun 13, 2017 at 14:16 UTC
    use Lchown; lchown $uid, $gid, @linknames or die "Can't 'lchown($uid, $gid, @linknames)': $!";

    See Lchown for details.