opscape

Files and directories

chown

Change the owner and/or group of files and directories.

chown [OPTION...] [OWNER][:[GROUP]] FILE...

12 of 12 examples run in Debian 13.7 on 2026-10-31 · coreutils 9.7-3 · manual: chown(1)

Every file belongs to one user and one group. chown OWNER file changes the user, chown OWNER:GROUP file both, and chown :GROUP file only the group (the same as chgrp). Owners and groups can be given as names or numeric IDs.

Giving a file away is reserved for root: an ordinary user cannot make a file belong to someone else, or the disk quota system and many security assumptions would fall apart. A regular user may only change a file's group, and only to a group they belong to. That is why chown usually appears with sudo, and why the examples here run as root.

The everyday cases are fixing ownership after copying files as root, handing a directory to a service account (chown -R www-data:www-data /srv/site), and restoring ownership on files extracted from an archive. Permission bits are a separate matter, set with chmod.

Examples

Ordinary users cannot give files away

chown root notes.txt
explain
outputexit 1
chown: changing ownership of 'notes.txt': Operation not permitted

Run as the regular dev user, the kernel refuses with "Operation not permitted". Changing ownership needs root (or the CAP_CHOWN capability).

Change the owner

Setup run before this example
useradd -M alice
chown alice notes.txt
ls -l notes.txt
output
-rw-rw-r-- 1 alice dev 190 Oct 25 05:30 notes.txt

The owner is now alice; the group (dev) is unchanged.

Change owner and group together

Setup run before this example
useradd -M alice
groupadd web
chown alice:web notes.txt
ls -l notes.txt
output
-rw-rw-r-- 1 alice web 190 Oct 25 05:30 notes.txt

OWNER:GROUP sets both in one call.

Change only the group

Setup run before this example
groupadd web
chown :web todo.txt
ls -l todo.txt
output
-rw-rw-r-- 1 dev web 62 Oct 24 21:28 todo.txt

With nothing before the colon, the owner stays and only the group changes, exactly what chgrp web todo.txt does.

Owner plus that user's login group

Setup run before this example
useradd -M -U alice
chown alice: notes.txt
ls -l notes.txt
output
-rw-rw-r-- 1 alice alice 190 Oct 25 05:30 notes.txt

A trailing colon with no group means "the owner's login group", here the alice group that useradd -U created.

Change a whole directory tree

Setup run before this example
useradd -M -U deploy
chown -R deploy:deploy src
ls -lR src
output
src:
total 3
-rw-rw-r-- 1 deploy deploy  49 Oct 28 03:10 Makefile
-rwxrwxr-x 1 deploy deploy 363 Oct 28 09:43 app.py
drwxrwxr-x 2 deploy deploy   3 Oct 28 06:26 lib
-rw-rw-r-- 1 deploy deploy  83 Oct 28 15:30 main.c
-rwxrwxr-x 1 deploy deploy 162 Oct 28 11:32 util.sh

src/lib:
total 1
-rw-rw-r-- 1 deploy deploy 88 Oct 28 07:32 helpers.py

-R applies the change to the directory and everything below it, the usual way to hand a project to a service account.

Report only what actually changed

Setup run before this example
useradd -M -U deploy
chown deploy:deploy data/users.csv
chown -c deploy:deploy data/*.csv
explain
output
changed ownership of 'data/sales.csv' from dev:dev to deploy:deploy

-c prints a line only for files whose ownership changed; users.csv already belonged to deploy, so only sales.csv is reported. -v would report every file.

Use numeric IDs

chown 1500:1500 todo.txt
ls -l todo.txt
output
-rw-rw-r-- 1 1500 1500 62 Oct 24 21:28 todo.txt

IDs need not exist in /etc/passwd. ls -l shows bare numbers when no name matches, which is what you see on files extracted from another machine's archive or mounted from another system.

Copy ownership from another file

Setup run before this example
useradd -M -U alice
chown alice:alice notes.txt
chown --reference=notes.txt todo.txt README.md
ls -l notes.txt todo.txt README.md
output
-rw-rw-r-- 1 alice alice 230 Oct 24 02:38 README.md
-rw-rw-r-- 1 alice alice 190 Oct 25 05:30 notes.txt
-rw-rw-r-- 1 alice alice  62 Oct 24 21:28 todo.txt

--reference takes the owner and group from notes.txt and applies them to the other files.

Change only files owned by a particular user

Setup run before this example
useradd -M -U alice
useradd -M -U bob
chown alice:alice todo.txt notes.txt
chown -v --from=alice bob todo.txt notes.txt README.md
explain
output
changed ownership of 'todo.txt' from alice to bob
changed ownership of 'notes.txt' from alice to bob
ownership of 'README.md' retained as dev

--from=alice acts only on files currently owned by alice; README.md belongs to dev and is retained, as -v reports.

A user name that does not exist

chown nobody2 notes.txt
explain
outputexit 1
chown: invalid user: ‘nobody2’

Names are looked up in the user database; an unknown name is an error. Numeric IDs are not checked.

Common pitfalls

  • chown -R user /path/* misses dotfiles at the top level because the glob does not match them. Use chown -R user /path (which also changes /path itself).

  • chown -R follows no symlinks by default, but chown on a single symlink name changes its target. Add -h when you mean the link.

  • Recursive chown on the wrong path (chown -R www-data / instead of ./) breaks a system in ways that are hard to undo. Double-check before pressing Enter.

  • On Linux, changing the owner of an executable clears its setuid and setgid bits, a deliberate safety rule; set them again afterwards if they are really needed.

GNU vs BSD and macOS

The examples above ran the GNU/Linux version. These are the differences that matter on macOS and the BSDs (written from their documentation, not run here).

  • OWNER.GROUP with a dot is an old, deprecated separator; use the colon everywhere.

  • --reference, --from and -c are GNU options. BSD/macOS chown has -R, -h, -v and the -H/-L/-P symlink controls.

Options worth knowing

A selection, described in our own words. For the full list, see chown(1) or chown --help.

OptionWhat it does
-R, --recursiveOperate on directories and everything below them.
-h, --no-dereferenceChange symlinks themselves, not their targets.
-v, --verboseReport every file processed.
-c, --changesReport only files whose ownership changed.
-f, --silentSuppress most error messages.
--reference RFILEUse RFILE's owner and group.
--from CURRENT_OWNER:CURRENT_GROUPChange only files that currently have this owner and/or group.
--dereferenceChange the targets of symlinks (the default).
--preserve-rootRefuse to operate recursively on /.
-HWith -R, follow a symlink given on the command line.
-LWith -R, follow every symlink to a directory.
-PWith -R, follow no symlinks (the default).

Related