chown
Permissions
Usage
sudo chown [user]:[group] [path]Changes a file's owner and group; only root may hand a file to someone else, which is why it almost always needs sudo.
Common flags
| Flag | Meaning |
|---|---|
| user:group | Set owner and group at once; :group alone sets only the group |
| -R | Apply to a whole tree |
| -h | Change the symlink itself, not what it points at |
| -v | Name each file as it changes |
| --reference | GNU: copy owner and group from another file |
Examples
sudo chown -R www-data:www-data /var/wwwHands the web root to the server user.
sudo chown :staff report.pdfChanges only the group.
sudo chown -R $USER ~/.npmTakes back a directory root created for you.
Numeric and symbolic modes name the same thing: 755 and u=rwx,go=rx are the same permission.
How to read this
- Square brackets [ ] mark a part you may leave out.
- An ellipsis … means you can list more than one.
- Flags are case-sensitive — in some commands -r and -R do different things.
Questions
Q. What does chown do?
Changes a file's owner and group; only root may hand a file to someone else, which is why it almost always needs sudo.
Q. How do I type it?
sudo chown [user]:[group] [path] — square brackets mark the parts you can leave out.
Q. How many flags are worth knowing?
5 are listed here; the full set is in man chown. This command sits under Permissions.
Related commands
man page: man chown