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 ln Command: Create Hard Links and Symbolic Links

Linux ln Command: Create Hard Links and Symbolic Links

Learn how to create hard links and symbolic links with Linux ln, choose relative or absolute targets, replace links safely, and inspect link behavior.

Linux last Command: Review Login and Reboot History

Linux last Command: Review Login and Reboot History

Learn how to use the Linux last command to review user login sessions, system reboots, and shutdown history, with essential options, practical examples, output interpretation, and common troubleshooting tips.

Linux shred Command: Overwrite File Data and Understand Its Limits

Linux shred Command: Overwrite File Data and Understand Its Limits

Learn how Linux shred overwrites file data, which options control its passes and removal, and why SSDs, snapshots, backups, and modern filesystems limit its guarantees.

Linux top Command: Monitor Processes in Real Time

Linux top Command: Monitor Processes in Real Time

Learn how to monitor Processes in Real Time with the Linux top command, including practical examples, key options, and important precautions.

Linux nohup Command: Keep a Command Running After Logout

Linux nohup Command: Keep a Command Running After Logout

Learn how to use the Linux nohup command to keep a command running after the terminal closes or the user logs out, with essential options, practical examples, output interpretation, and common troubleshooting tips.

Linux tree Command: Display a Directory Tree

Linux tree Command: Display a Directory Tree

Learn how to use the Linux tree command to display directory contents as a readable hierarchy and control depth and filtering, with essential options, practical examples, output interpretation, and common troubleshooting tips.

Linux fold Command: Wrap Long Lines at a Fixed Width

Linux fold Command: Wrap Long Lines at a Fixed Width

Learn how to wrap Long Lines at a Fixed Width with the Linux fold command, including practical examples, key options, and important precautions.

Linux man Command: Read Command Manual Pages

Linux man Command: Read Command Manual Pages

Learn how to use the Linux man command to find and read command manuals, sections, options, and related pages, with essential options, practical examples, output interpretation, and common troubleshooting tips.

Linux whoami Command: Show the Effective User Name

Linux whoami Command: Show the Effective User Name

Learn how to show the Effective User Name with the Linux whoami command, including practical examples, key options, and important precautions.

Linux ip Command: Inspect and Configure Network Interfaces and Routes

Linux ip Command: Inspect and Configure Network Interfaces and Routes

Learn how to inspect and Configure Network Interfaces and Routes with the Linux ip command, including practical examples, key options, and important precautions.