Hi.
So in this lesson we are going to understand a command which is change owner c h own.
This command is used to change the user and the group ownership for any file or directory.
The syntax is change owner the user name that needs to be given to any file.
Similarly to a directory, we can also change the group names which can be done using a semicolon.
We'll also see how we can change the owner and the group recursively for directories wherein there are
multiple files inside a directory.
So it's the practical time and let's see how we use change owner.
I'm onto my terminal right now and I have created two files called this file one, file two and a directory
called a directory one.
Let us see the permissions.
Currently the files have been created using the user root and the group root.
Also, the directory has been created by the user route and the group route.
Now we're going to change the owners of or ownership of these files and directories when we use the
command ls hyphen l r.
It shows us recursively what is inside directory one as we can see inside directory one there are two
more files called as file one and file two.
Great.
Now let us change the ownership of these files one by one and observe.
So the first thing that I'm going to do is I'm going to change the owner of file one, which is route
to another user.
So let's change the ownership of this file from the user route to hacked ify and give the file name
as file one.
Let us verify that our changes have been completed or no.
And we can see successfully the C own command got executed and we have changed the ownership of the
file one.
Now let us do the same thing for file two.
So I'm going to use the command C zone again, but this time we're going to change the group.
The group is root.
We are changing the group to Curly, which is followed by a semicolon.
Let's see again.
And we can see this was the first file one.
Now for file two, this group ownership has been changed from root to curly.
Great.
Let us do one thing.
Let us create an empty file using the command touch, which is file three.
As we can see, the user and the group both are root because currently the root user is logged in,
which has created this empty file known as file three.
Let's change the ownership of this file.
Let's say the user be hacked ify.
So the command is going to be c h own rectify.
Also change the group ownership to another which is Kali for file three.
Now as we can see, when we ran the command, the user and group both have changed.
We can verify that also with hyphen V, which stands for Verbose, which gives us more output of what
the command is doing in the background.
As here we can see the ownership of file three retained as hacked ify and Kali.
Now let us again run this command.
This time you're going to change the ownership of the user of file two.
We are going to say C own.
The user should be curly and hyphen V, which is verbose, which shows the message that the ownership
changed from root to curly.
Let us see.
Now the directory.
As you can see, the directory has the user route and group route.
Let's go inside that directory by using the command change directory city.
Here we can see that there are two files called this file one, file two, which has the same user and
group which was applied to directory one.
This time we will see how we can recursively change the user and the group ownership of directories
and files.
So for that you're going to use the command C phone hyphen capital R, which stands for recursive.
Let's give the user ownership as Rectify and group as Kali to directory one before.
As we can see, it was root and root.
Now let's hit enter with hyphen V, which will show us what is happening in the background and we can
see the changed ownership has successfully completed.
Let's verify using the command ls hyphen l capital r which shows us the list and we can see successfully
the directory user and group ownership and the files inside that directories has also been changed.
So I hope you guys understood this.
Thank you.