Linux has numerous way on which you can manage file owners and their groups. Every single time you create a new file, it is assigned on to default user account on your machine. In this article, check how you can change file owner and group in Linux using chown command?
What is chown?
The chown command is a Linux command that allows us to change user and group ownership of each given file. For more on chown command, make sure to read the man page using the following command.
# man chown
For the purpose of this article I have created a kings.txt file which resides inside the kings directory. My goal is to change the user and group of this file to a new user and group. First of all, let's list a kings.txt to see it's main user and group to which it bellongs. We can do that by using the following command.
# ls -l kings.txt
On above image, you can see that I have listed the content of kings.txt file using cat command and listed it's permissions using ls commands. Down bellow in left corner you can see -rw-rw-r as well as amar amar.
First amar designates the owner of the file, while second amar designates the group to which file belongs. Our goal is to change the file kings.txt owner and group. Now, I have created a list of kings on ancient Near East during 1400 BC and on the first place we have Abdi-Aširta, king of land of Amurru during 1400 BC. It was geographical area which covered a bigger part of modern day Syria.
Before we change the ownership of the file, let us list the groups on a machine. To do that, simply type in the following command.
# cat /etc/group
Note that at the bottom of this figure, there is a group by the name of amurru and there is a user of that group by the name of 'abdi'. So, let us change the kings.txt to a user 'abdi' and group 'amurru'. Here's the command.
There you go. We have successfully changed the kings.txt owner and group. Now you know how you can change file owner and group in Linux? If you like this article, leave a comment down bellow, share it and till next time.
Nema komentara:
Objavi komentar