chown
The chown (change owner) command is used to change the user owner and/or the group owner of a given file, directory, or symbolic link. Typically, only the root user can change the ownership of a file to another user.
Basic Syntax
chown [OPTION]... [OWNER][:[GROUP]] FILE...
Common Options
| Option | Description |
|---|---|
-R, --recursive | Operate on files and directories recursively. |
-v, --verbose | Output a diagnostic for every file processed. |
-c, --changes | Like verbose but report only when a change is made. |
--reference=RFILE | Use RFILE's owner and group rather than specifying them. |
Real-world Examples
-
Change the owner of a file:
sudo chown john document.txt -
Change both the owner and group of a file:
sudo chown john:developers project.zip -
Change only the group of a file:
sudo chown :developers shared_folder(Similar to
chgrp) -
Change ownership recursively for a directory:
sudo chown -R www-data:www-data /var/www/html/