• Home
  • Linux
  • Ubuntu
  • Debian
  • CentOS
  • Linux Commands
  • About Us
  • Donate
TecNStuff
Menu
  • Home
  • Linux
  • Ubuntu
  • Debian
  • CentOS
  • Linux Commands
  • About Us
  • Donate

Chown Command in Linux

Written by Admin, Updated On June 11, 2019
chown, linux commands, terminal
Chown Command in Linux

Linux is designed to support a large number of users. Because of this, it should maintain access permissions to files and directories. Also need how users can access these files and directories. The chown command is used to change the user and group ownership of a given file, directory or link. In this tutorial we will show you how to use chown command in Linux.

Chown Command Syntax#

Before going into how to use the chown command, let’s start by reviewing the basic syntax.

chown [OPTIONS] OWNER[:GROUP] FILE(s)

Where,

  • OPTIONS = Different options provided for Chown command given here.
  • OWNER = OWNER is the username or you can also provide UID (UserID) of specific user.
  • GROUP = GROUP is the name of the new group or the group ID.
  • FILE = FILE is the name of one file or multiple files.

Make sure your user account have sudo privileges then only you can change the ownership of a file.

How to Change the Owner of a File and Directory#

You can use simply chown command to change the ownership of files or directories. Following are the few example with different scenarios:

For example, below command will change the ownership of a file to a specific user tecnstuff:

chown tecnstuff test.txt

You also can change the ownership of multiple files or directories by specify space separate list. Following command will change the ownership of multiple files test.txt and test1.txt

chown tecnstuff test.txt test1.txt dir1

There is another way to define owner using user id (UID) instead of username. Below command will change the ownership of file to user tecnstuff:

chown 7002 test1.txt

How to Change the Owner and Group of a File#

You can change the both owner and the group of a file using chown command. Chown command followed by the new owner and group separated by colon with no intervening spaces.

Below command will change the ownership of a file test.txt to a new owner tecnstuff and group users.

chown tecnstuff:users test.txt

If you have not specified the group name then by default it will assign user’s login group.

chown tecnstuff: test.txt

Change Group of the file#

You can change the only group of the file using chown command. You just need to provide only specific group name.

For example, if you want to change group of test.txt file from users to www-data then run below command:

chown :www-data test.txt

Change Ownership of Files Recursively#

You can use -R option along with chown command to change group or owner of all file and sub-directories in a specific directory.

Run below command if you wants to change group of all directories inside /var/www to a new owner and group named www-data:

chown www-data: /var/www

Conclusion#

Finally, you successfully learned how to use the chown command in Linux. If you want to learn more about the chown command visit the chown man page.

If our content helps you, please consider buying us a coffee

Thank you for your support.

Share On
Share on Facebook
Share on Twitter
Share on Reddit
Share on Tumblr
 Previous Article How to Install Git on CentOS 7 System
Next Article   Uptime Command in Linux With Example

Related Posts

  • How to Install SSH Keys on Ubuntu 22.04

    How to Set up SSH Keys on Ubuntu 22.04

    January 7, 2023
  • How to Install Fail2ban on Ubuntu 22.04

    How to Install and Configure Fail2ban on Ubuntu 22.04

    December 5, 2022
  • How to Enable SSH on Ubuntu 22.04

    How to Enable SSH on Ubuntu 22.04

    December 1, 2022

Leave a Reply Cancel reply

DigitalOcean Referral Badge

Popular Posts

  • How to Install SSH Keys on Ubuntu 22.04
    How to Set up SSH Keys on Ubuntu 22.04 January 7, 2023
  • How to Install Mongodb on Debian 11
    How to Install MongoDB on Debian 11 Linux January 11, 2023
  • How to Install Puppet Agent on Ubuntu 22.04
    How to Install Puppet Agent on Ubuntu 22.04 January 22, 2023
  • How to Install Jenkins on Debian 11
    How to Install Jenkins on Debian 11 January 5, 2023
  • How to Change-Hostname Ubuntu 22.04
    How to Change Hostname on Ubuntu 22.04 January 19, 2023
© 2020 TecNStuff All rights reserved. This website is using and storing cookies on your browser. By using this website you agree our Privacy Policy.  Follow us -  Twitter | Facebook