chown Command in Linux

Post Reply
admin
Site Admin
Posts: 1
Joined: Thursday 9. April 2026, 09:28

chown Command in Linux

Post by admin »

The chown command in Linux allows modifying the ownership of files or directories. It can assign a new user, group, or both, either individually or simultaneously. Only the root user or the file owner with permissions can perform ownership changes.
  • Changes the owner and/or group of files or directories.
  • Supports recursive changes with the -R option for directories.
  • Can change ownership of single or multiple files at once.
  • Offers verbose reporting and conditional ownership change using options.
  • Works with symbolic links using dedicated options (-h, -H, -L, -P).
Synopsis
chown [OPTION]... [OWNER][:[GROUP]] FILE...
chown [OPTION]... --reference=RFILE FILE...

Core Syntax
chown [OPTIONS] [OWNER]:[GROUP] FILE

Change Owner: chown user1 file.txt
Change Owner and Group: chown user1:group1 file.txt
Change Group Only: chown :group1 file.txt or chown .group1 file.txt
Change Owner to User's Login Group: chown user1: file.txt

Common Options

-R (Recursive): Changes ownership of directories and their contents recursively.
-v (Verbose): Shows diagnostic messages for every file processed.
-c (Changes): Similar to verbose, but reports only when changes are made.
--reference=RFILE: Sets ownership to that of a reference file.

Common Use Cases

Changing Ownership Recursively:
sudo chown -R www-data:www-data /var/www/html

This changes the user and group to www-data for all files in the directory.

Changing Only the Group:
chown :newgroup file.txt

Using Numeric UIDs:
chown 1000:1000 file.txt

Changes owner and group to the user/group with ID 1000
Post Reply