How to change the file owner and group in Linux?

To change the file owner and group, we use the chown command in the Linux operating system. Linux is a multiuser operating system where every file and directory belongs to an owner and group. The chown command allows administrators to transfer ownership and group membership of files and directories.

Syntax

The general syntax of the chown command is as follows −

chown [OPTION]... [OWNER][:[GROUP]] FILE...
chown [OPTION]... --reference=RFILE FILE...

Common Options

Option Description
-c, --changes Gives a diagnosis for all files that actually changed
-f, --silent, --quiet Suppresses most error messages
-v, --verbose Gives a diagnosis for all processed files
-R, --recursive Changes files and directories recursively
--help Displays help message and exits
--version Shows version information and exits

Checking Current Ownership

Before changing ownership, check the current owner and group using the ls -l command −

ls -l filename
-rw-rw-r-- 1 vikash vikash 34 Jan 11 20:59 file.txt

The output shows vikash as both owner and group.

Examples

Changing File Owner Only

To change only the owner of a file, use −

sudo chown gautam file.txt
vikash@tutorialspoint:~/shadow$ sudo chown gautam file.txt
[sudo] password for vikash:
vikash@tutorialspoint:~/shadow$ ls -l file.txt
-rw-rw-r-- 1 gautam vikash 34 Jan 11 20:59 file.txt

Changing Owner and Group Together

To change both owner and group simultaneously −

sudo chown gautam:developers file.txt

Changing Group Only

To change only the group, leave the owner part blank −

sudo chown :developers file.txt

Recursive Changes

To change ownership of a directory and all its contents −

sudo chown -R gautam:developers /path/to/directory

Alternative Method − chgrp Command

For changing only group ownership, you can also use the chgrp command

sudo chgrp developers file.txt

Key Points

  • Administrative privileges (sudo) are required to change ownership

  • Use colon (:) to separate owner and group names

  • Omitting owner changes only the group

  • The -R flag applies changes recursively to directories

  • Always verify changes using ls -l

Conclusion

The chown command is essential for managing file ownership in Linux systems. It provides flexible options to change owners, groups, or both, with recursive capabilities for directories. Combined with chgrp, these tools ensure proper file access control in multiuser environments.

Updated on: 2026-03-17T09:01:38+05:30

29K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements