chown — Change File Owner and Group¶
Overview¶
chown (change owner) changes the user owner and/or group owner of files, directories, or symbolic links. Ownership management is fundamental for configuring service access control in Linux.
Command type: External (GNU coreutils)
Location: /usr/bin/chown
Standard: POSIX.1-2017
Syntax¶
Examples¶
Change User Ownership Only¶
Change Both User and Group Ownership¶
# Set owner to 'www-data' and group to 'www-data'
chown www-data:www-data /var/www/html
# Shorthand: trailing colon sets group to user's primary group
chown www-data: /var/www/html
Change Group Ownership Only¶
Recursive Ownership Updates¶
Copy Ownership from Reference File¶
Symlink Ownership¶
By default, chown operates on the target of a symlink, not the symlink itself. Use -h to change the ownership of the symlink file:
Interview Questions¶
How do you change the group owner of a file without changing the user owner?
Prefix the group name with a colon or dot: chown :developers file.txt (or use chgrp developers file.txt).
What is the difference between chown -R and chown -h?
-R operates recursively down directory trees. -h changes the ownership of a symbolic link itself rather than the target file it points to.
Related Commands¶
| Command | Description |
|---|---|
chmod | Change file permissions |
chgrp | Change group ownership specifically |
ls -l | Display file ownership and group |