Hi.
So in this lesson, we are going to understand a command
which is change owner.
CH own
this command is used to change the user and
the group ownership for any file
or directory.
The syntax is change owner the username.
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 to
use change owner.
I want to my terminal right now and I have created.
two files called as file 1 File 2 and a
directory called as directory 1
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 root
and the group root.
Now we are going to change the owners
of odd ownership of this
files and directories.
when we use the command LS - L are it
shows us recursively what is
inside directory 1 as we can
see inside directory 1 there are two more files called
as file 1 and file 2
great.
Now, let's 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 1
which is root to another user.
So let's change the ownership of this file from the
user root to hacktify and
give the file name as file 1.
Let us verify that our changes
have been completed or no, and we can see successfully the
CH own command got executed
and we have changed the ownership of
the file one.
Now let us do the same thing for File
2.
So I'm going to use the command CH own again,
but this time we're going to
change the group.
The group is root. We are changing the group to Kali which
is followed by a semicolon.
Let's see again, and we can see this was
the first file one now for File 2 this group
ownership has been changed from
root to Kali.
Great.
Let us do one thing. Let us create an empty file
using the command touch, which is file 3.
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 3
Let's change the ownership of this file.
Let's say the user be hackedify. So
the command is going to be CH on actify all
so change the group ownership
to another which is Kali for
file 3.
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 3
retained as hactify.
and Kali
now
let us again run this command.
This time we're going to change the ownership
of the user of file
2. We are going to say CH on
the user should be Kali and hyphen
V which is verbose which shows
the message that the ownership changed from
root to Kali.
Let us see now the directory.
As you can see the directory has the user root
and group root.
Let's go inside the directory.
By using the command change directory CD here. We
can see that there are two files called as file
one file to which has the same user
and group which was applied to directory 1
This time we will see how we can recursively change
the user and the group
ownership of directories and files.
So for that we are going to use the command ch1 capital
r which stands for
recursive.
Let's give the user ownership as hackedify
and group as Kali to directory 1.
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.