Linux chown Command: Change File Owner and Group

chown changes the owner user and owner group of a file or directory. It is useful when aligning the ownership of service data directories, but incorrect recursive application can block service access.

What is the chown command?

Specifying owner:group changes both attributes together, and specifying only the owner usually leaves the group unchanged. Permissions to change are limited according to system policy and generally require administrative privileges. The access permission bits themselves are managed with chmod.

Basic syntax

chown [options] owner[:group] file...

Installed implementations and options may vary by distribution. Check the description for the current system with man chown.

Examples

Change owner only

Set the file owner according to the account. For important system paths, verify the target first.

sudo chown alice report.txt

Change both owner and group

Specify user and group to reduce ambiguity.

sudo chown alice:editors report.txt

Check change results

Check the owner and group and change only if necessary.

stat -c '%U:%G %n' report.txt

Checking the result of owner and group change

The following example assumes that the alice user and the developers group actually exist. Changing ownership usually requires administrator privileges.

sudo chown alice:developers demo.txt
stat -c '%U:%G %n' demo.txt

Example output:

alice:developers demo.txt

When chown is successful, there is usually no output, so check the result with stat or ls -l. -R applies to the entire directory below, so make sure to check the path and how symbolic links are handled before using it on a web root or system directory. Changing ownership can alter service access policies.

In containers and network filesystems, the same account name can map to different numeric UIDs or GIDs. For automation, compare id user with the target's stat -c '%u:%g' output. Arbitrary ownership changes to service files can break the service's ability to read, write, or execute them.

Main Options and Format

Options/Format Description
-R Recursively change ownership of subitems.
-h Target the symbolic link itself instead of the link's target.
--reference=file Copy the owner and group of the referenced file.
-v Show detailed information on processed files.

Precautions when using

Incorrectly specifying a single path in chown -R can change ownership of many files at once. First, check the scope with stat or find, and if possible, apply only to a narrow path. Handling symbolic links and special permission bits may be affected by the file system and options.

Frequently Asked Questions

What is the difference between chown alice report.txt and chown alice:editors report.txt?

The first changes only the owner, while the second specifies both the owner and the group.

Official Documentation

The exact behavior of the options and differences between implementations can be found in the official chown documentation.

More in This Category
Linux ssh-copy-id Command: Install a Public Key on a Remote Account

Linux ssh-copy-id Command: Install a Public Key on a Remote Account

Learn how to install a Public Key on a Remote Account with the Linux ssh-copy-id command, including practical examples, key options, and important precautions.

Linux groups Command: Show a User's Group Memberships

Linux groups Command: Show a User's Group Memberships

Learn how to show a User's Group Memberships with the Linux groups command, including practical examples, key options, and important precautions.

Linux Tutorial / Standard Input, Output, Redirection, and Pipes

Linux Tutorial / Standard Input, Output, Redirection, and Pipes

Understand standard input, output, and error; practice file redirection and pipes; and learn why overwrite risk and redirection order matter.

Linux df Command: Check Filesystem Free Space

Linux df Command: Check Filesystem Free Space

Learn how to check Filesystem Free Space with the Linux df command, including practical examples, key options, and important precautions.

Linux zip Command: Create ZIP Archives

Linux zip Command: Create ZIP Archives

Learn how to create ZIP Archives with the Linux zip command, including practical examples, key options, and important precautions.

Linux nice Command: Set a New Process's Scheduling Priority

Linux nice Command: Set a New Process's Scheduling Priority

Learn how to set a New Process's Scheduling Priority with the Linux nice command, including practical examples, key options, and important precautions.

Linux Tutorial / What Is Linux? Understanding the Kernel, Distributions, and Open Source

Linux Tutorial / What Is Linux? Understanding the Kernel, Distributions, and Open Source

Understand how the Linux kernel differs from a distribution, what user space and open source mean, and how to check your system's kernel and distribution versions.

Linux mkfs Command: Create a New Filesystem

Linux mkfs Command: Create a New Filesystem

Learn how to create a New Filesystem with the Linux mkfs command, including practical examples, key options, and important precautions.

Linux find Command: Search Files by Name, Type, Size, and Time

Linux find Command: Search Files by Name, Type, Size, and Time

Learn how to search with Linux find by name, file type, size, and modification time, combine expressions, run commands safely, and verify targets before deletion.

Linux history Command: Review and Reuse Shell Command History

Linux history Command: Review and Reuse Shell Command History

Learn how to use the Linux history command to review, search, reuse, and manage shell command history, with essential options, practical examples, output interpretation, and common troubleshooting tips.