In this lesson, we're going to discuss
how you can assign ownership to files and directories.
In Linux, ownership refers to the property
by which a user can apply and modify permissions
of a file or directory.
By default, the owner of the file or directory
is the user who created the file or directory.
Other than the superuser who's known as our root user,
no other user can change their permissions of an object
that's owned by somebody else.
While the most common application of ownership
is going to be the changing of the read, right,
or execute permission attributes,
owners can also alter advanced and special permissions
of the objects they own.
These objects are files and directories.
Now, remember, every file is owned by a specific user
or a specific group.
If you need to change the owner of the file or directory,
you can use the chown command.
Now, the chown command is used to change the owner,
the group, or both for a file or directory.
At times, you may wish that somebody else
is going to manage an object's permissions
other than the user who created that object.
To do that, just enter the chown command
by doing chown username and the file or directory name.
This will change the owner, but not the group.
If you want to change the owner and the group
for a file or directory,
you can enter chown username : group name
and then the file or directory name.
If you want to change the owner and then assign the group
to the new owner's login group, you can do that
by using chown username : file or directory name.
If you need to change the group, but not the owner
you can do that by typing in
chown : group name file or directory name.
Did you notice there's always the same basic format here?
It's chown username : group name
and then file or directory name.
This way we can assign either part or both parts
depending on which ones we put in as our options.
We simply leave the username or group blank
if we don't want to change those things
and we add the other one in
if we want to change the username or group name.
You can also use the chown command recursively
to change ownership throughout a directory structure
if you add the dash R option.
The next command we have is known as chgrp.
The chgrp command or C-H-G-R-P
is going to be used to change the group ownership
of a file or directory.
Changing the group ownership of an object
ensures the group permissions
are applied to the specific group.
The proper way to enter the chgrp command
is to enter chgrp the group name
and the file or directory name.