Change file owner and group.
The chown command changes the user and/or group ownership of files and directories. Only the superuser can change the owner of a file; the owner of a file can change the group to any group of which that owner is a member.
The owner and group can be specified as names or numeric IDs. The format is owner:group, and either part can be omitted. If only the owner is given, the group is not changed. If the owner is followed by a colon but no group, the group is changed to the owner's login group.
With the -R option, chown operates recursively on directories and their contents.
| Name | Description | Optional |
|---|---|---|
owner[:group] |
The new owner and optionally the new group, separated by a colon. | No |
file |
One or more files or directories whose ownership is changed. | No |
-R |
Change ownership recursively for directories and their contents. | Yes |
chown alice file.txt
chown alice:staff project/
chown -R www-data:www-data /var/www