- Changes the owner and/or group of files or directories.
- Supports recursive changes with the -R option for directories.
- Can change ownership of single or multiple files at once.
- Offers verbose reporting and conditional ownership change using options.
- Works with symbolic links using dedicated options (-h, -H, -L, -P).
chown [OPTION]... [OWNER][:[GROUP]] FILE...
chown [OPTION]... --reference=RFILE FILE...
Core Syntax
chown [OPTIONS] [OWNER]:[GROUP] FILE
Change Owner: chown user1 file.txt
Change Owner and Group: chown user1:group1 file.txt
Change Group Only: chown :group1 file.txt or chown .group1 file.txt
Change Owner to User's Login Group: chown user1: file.txt
Common Options
-R (Recursive): Changes ownership of directories and their contents recursively.
-v (Verbose): Shows diagnostic messages for every file processed.
-c (Changes): Similar to verbose, but reports only when changes are made.
--reference=RFILE: Sets ownership to that of a reference file.
Common Use Cases
Changing Ownership Recursively:
sudo chown -R www-data:www-data /var/www/html
This changes the user and group to www-data for all files in the directory.
Changing Only the Group:
chown :newgroup file.txt
Using Numeric UIDs:
chown 1000:1000 file.txt
Changes owner and group to the user/group with ID 1000