Home·Terminal commands

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

FlagMeaning
user:groupSet owner and group at once; :group alone sets only the group
-RApply to a whole tree
-hChange the symlink itself, not what it points at
-vName each file as it changes
--referenceGNU: copy owner and group from another file

Examples

sudo chown -R www-data:www-data /var/www

Hands the web root to the server user.

sudo chown :staff report.pdf

Changes only the group.

sudo chown -R $USER ~/.npm

Takes 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