# perldoc > chown

---
type: CommandReference
command: chown
mode: perldoc
section: ""
source: perldoc
---

## Quick Reference
- `chown $uid, $gid, @files` — change owner and group of file list, returns number of files changed.

## Name
Changes the owner (and group) of a list of files. The first two elements must be numeric uid and gid; `-1` leaves that value unchanged.

## Synopsis
perl
my $cnt = chown $uid, $gid, 'foo', 'bar';
chown $uid, $gid, @filenames;
## Options
- `$uid` — numeric user ID (use `-1` to leave unchanged)
- `$gid` — numeric group ID (use `-1` to leave unchanged)
- `@files` — list of filenames and/or filehandles (pass as glob or globref; barewords treated as filenames). On systems supporting `fchown(2)`, filehandles are accepted; otherwise raises exception.

## Examples
Interactive example:
perl
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);
chown $uid, $gid, @ary;
## See Also
- `fchown(2)` (on systems supporting it)
- "chown" in `perlport` (portability issues)

## Return Value
Returns the number of files successfully changed (integer). On failure, returns `undef` and sets `$!`. On most systems, only superuser can change owner; group can be changed to any of the caller's secondary groups.