perl-5.38.0
chown LIST

Changes the owner (and group) of a list of files. The first two elements of the list must be the numeric uid and gid, in that order. A value of -1 in either position is interpreted by most systems to leave that value unchanged. Returns the number of files successfully changed.

LIST に含まれるファイルの所有者 (とグループ) を変更します。 LIST の最初の二つの要素には、数値表現 の uid と gid を この順序で与えなければなりません。 どちらかの値を -1 にすると、ほとんどのシステムではその値は 変更しないと解釈します。 変更に成功したファイルの数を返します。

    my $cnt = chown $uid, $gid, 'foo', 'bar';
    chown $uid, $gid, @filenames;

On systems that support fchown(2), you may pass filehandles among the files. On systems that don't support fchown(2), passing filehandles raises an exception. Filehandles must be passed as globs or glob references to be recognized; barewords are considered filenames.

fchown(2) に対応しているシステムでは、ファイルハンドルを引数として渡せます。 fchown(2) に対応していないシステムでは、ファイルハンドルを渡すと 例外が発生します。 ファイルハンドルを認識させるためには、グロブまたはリファレンスとして 渡されなければなりません; 裸の単語はファイル名として扱われます。

Here's an example that looks up nonnumeric uids in the passwd file:

passwd ファイルから数値表現でない uid を検索する例を 示します:

    print "User: ";
    chomp(my $user = <STDIN>);
    print "Files: ";
    chomp(my $pattern = <STDIN>);

    my ($login,$pass,$uid,$gid) = getpwnam($user)
        or die "$user not in passwd file";

    my @ary = glob($pattern);  # expand filenames
    chown $uid, $gid, @ary;

On most systems, you are not allowed to change the ownership of the file unless you're the superuser, although you should be able to change the group to any of your secondary groups. On insecure systems, these restrictions may be relaxed, but this is not a portable assumption. On POSIX systems, you can detect this condition this way:

ほとんどのシステムでは、スーパーユーザーだけがファイルの所有者を 変更できますが、グループは実行者の副グループに変更できるべきです。 安全でないシステムでは、この制限はゆるめられています; しかしこれは 移植性のある仮定ではありません。 POSIX システムでは、以下のようにしてこの条件を検出できます:

    use POSIX qw(sysconf _PC_CHOWN_RESTRICTED);
    my $can_chown_giveaway = ! sysconf(_PC_CHOWN_RESTRICTED);

Portability issues: "chown" in perlport.

移植性の問題: "chown" in perlport