chown
Overview
chown changes file owner and/or group. Often paired with chmod when fixing service data directories.
Syntax
chown [options] owner[:group] file...
chown [options] :group file...
chown [options] --reference=rfile file...Common Options
| Option | Description |
|---|---|
-R |
Recursive |
-h |
Affect symlink itself, not target |
-v / -c |
Verbose / only when changed |
--from=o:g |
Only if current owner matches |
--preserve-root |
Do not recurse on / |
Safety
Recursive chown on / or large trees can break a system. Prefer narrow paths. Preserve root with --preserve-root (default for recursive in modern coreutils).
Examples with Explanations
Owner and group
sudo chown alice file.txt
sudo chown alice:developers project/
sudo chown :developers file.txt # group only
sudo chown -R www-data:www-data /var/www/appNumeric IDs
sudo chown 1000:1000 file.txtOnly if currently root-owned
sudo chown --from=root:root alice:alice file.txtReference
sudo chown --reference=good.txt bad.txtSymlinks
sudo chown -h alice linknameNotes
- Names resolve via NSS (
getent passwd); IDs work offline.
- Sticky/setuid bits interact with ownership — know your security model.
- ACLs (
setfacl) may still grant access beyond owner/group/other.