Glossary

chown

chown ("change owner") sets the user and/or group ownership of one or more files. Only root can change a file's user; an ordinary user can change the group only to one they are a member of.

sudo chown alice file.txt            # change owner
sudo chown alice:developers file     # owner and group
sudo chown :developers file          # group only
sudo chown -R alice /home/alice      # recursive
sudo chown --reference=/etc/hostname file  # copy ownership

Related commands include chgrp (change group only, no special privileges needed if you own the file and are in the target group) and id (show the current user's UID, GID, and supplementary groups). The ownership of a file, together with its mode bits, determines who can read, write, and execute it.

A common recovery task after extracting archives as root or copying files between users is to fix ownership recursively: sudo chown -R $USER:$USER ~/project/ resets a whole tree. Getting this wrong on a system directory can be catastrophic, so chown -R on anything outside your own files warrants caution.

Related terms: chmod

Discussed in:

Also defined in: Textbook of Linux