The CHOWN command in Linux is used for changing the ownership of a file. This ownership can be at the user level as well as at the group level since a file in Linux always belongs to a certain user and a certain group.
Here at LinuxAPT , we shall look into the usage of the CHOWN command in Linux.
To begin, before using the CHOWN syntax, run it's help command by executing:
$ chown --help
Once you run this command, you will know it's basic usage.
Here, we will change the ownership of a single file in Linux. To achieve this, begin by listing all the files of our Home directory with the help of the below command:
$ ls –l
This command will list all the files of the given directory.
For example, if you have a file named "testfile.txt", you can change the ownership of the file from "system" to "system2" by running the below command:
$ sudo chown system2 testfile.txt
Here, "system2" represents the name of the new owner.
This command will not produce any output on the terminal.
Therefore to confirm if the ownership of the said file has been changed successfully or not, you will have to run the "ls -l" command again.
You will see that the ownership of the said file has successfully been changed to "system2".
Here, if you want the change of ownership to be displayed in the output of the CHOWN command, simply execute the below command:
$ sudo chown –c system2 testfile.txt
Now, you will see the change of ownership of the file.
You can use the CHOWN command for modifying the group to which a file belongs in Linux with the below command:
$ sudo chown –c :system2 testfile.txt
This will change the group ownership of the file named "testfile.txt" to "system2".
In order to change both the ownership as well as the group to which the file belongs at once, run the below command:
$ sudo chown –c system2:system2 testfile.txt
This command will change the ownership as well as the group to which the file "testfile.txt" belongs to "system2".
This article covers the basic usage of the CHOWN command in Linux.In fact, you can now change the ownership of a file in system at the user level as well as at the group level. Also, with the chmod command command , you can change file access permissions such as read, write, and access.