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 Info:

Rakesh (He/Him) has over 14+ years of experience in Web and Application development. He is the author of insightful How-To articles for Code2care.

Follow him on: X

You can also reach out to him via e-mail:

Copyright ยฉ Code2care 2024 | Privacy Policy | About Us | Contact Us | Sitemap