How to change file or directory owner in Linux

Each file or directory in Linux has an owner, group, and permissions that allow who can read, write, and execute the file.

If you wish to change the owner for a file or directory, you can make use of the chown command. Using the chown command you can change both the owner user and the owner group for a file or directory.

Note: Superuser (root) privileges are required to change ownership of files that you don't own.

sudo chown <new-user-name>:<new-user-group> file/directory

Example 1 : Change owner only


    sudo chown code2care /Users/c2ctech/data/data.csv


    sudo chown code2care /Users/c2ctech/data

Example 2: Change owner group only


    sudo chown :devs /Users/c2ctech/data/data.csv


    sudo chown :devs /Users/c2ctech/data

Example 3: Change both owner and group


    sudo chown code2care:devs /Users/c2ctech/data/data.csv


    sudo chown code2care:devs /Users/c2ctech/data
How to change the owner of a file or directory in Linux


Facing issues? Have Questions? Post them here! I am happy to answer!

Author: Rakesh
Author Info:

Rakesh is a seasoned developer with over 10 years of experience in web and app development, and a deep knowledge of operating systems. Author of insightful How-To articles for Code2care.

Follow him on: X

Copyright © Code2care 2023 | Privacy Policy | About Us | Contact Us | Sitemap