← All commands
THE COMMAND REFERENCE

chown

Change the owner and group of files.

Last updated

GNU

Implementation-level reference; examples are not certified for every installed version.

Overview

chown changes who owns a file, and with a colon, its group too. Ownership decides which permission bits apply to you. Normal users cannot give files away, so changing the owner to someone else usually needs administrator rights; the examples change a file to its current owner so that they are safe to run.

Background

Today the name covers GNU chown, the chown that macOS ships (in /usr/sbin), and the chown applet in BusyBox. The macOS manual gives no date for it. They agree on OWNER, OWNER:GROUP and -R.

Examples

Set the owner to yourself, which is always allowed:

chown "$(id -u)" notes.txt && echo ok

Set the owner and the group together with a colon:

chown "$(id -u):$(id -g)" notes.txt && echo ok

Check the owner afterwards; ls -l shows it in the third column:

chown "$(id -u)" notes.txt && test "$(ls -l notes.txt | awk '{print $3}')" = "$(id -un)" && echo yes

Apply it to a folder and everything inside it with -R:

chown -R "$(id -u)" projects logs && echo ok

Options

-R
Change the owner of folders and everything inside them.

--reference
Use the owner and group of this file instead of naming them.

Common mistakes

chown -R on the wrong folder can change the owner of thousands of files, and it has no undo; check the path first. Be careful with -R and symbolic links, because a link can lead outside the folder you meant. Giving a file to another user is a one-way move for a normal user, since only an administrator can take it back. Use chmod for permissions; chown does not change them.

Portability

Only owner, OWNER:GROUP and -R are in the Common examples, using your own IDs. The old OWNER.GROUP spelling with a dot is not portable. The examples use numeric IDs from id, which work everywhere. The Common examples were executed on GNU coreutils 9.11, macOS system tools, and BusyBox 1.37.0 (see the development guide for the exact check).

About GNU chown

GNU chown is part of GNU coreutils, and this page's checks ran coreutils 9.11. --reference=FILE copies the owner and group of another file.

References

Original explanations, with upstream documentation for further reading. FreeBSD references are comparison material, not a claim of Apple version equivalence.