So that's neat, but let's say I want to own that file. let's say that file was created
under
administrator priviledges but I want to own it forever.
So, I'm gonna type sudo chown nick:nick
and the file that I want to perform that on is that.
Let's say I want to switch the permissions back to 644.
I will retain ownership so I'll be able to
write to it as the first column has rewrite access
for nick
and that's me.
So I no longer need this group column there as well.
So what I'm gonna type is,
sudo chmod 644 file.txt
and if I run ls again,
I can see that the permissions have been changed back
so that only the owner of the file
can write to it.
Cool.
Now I'm gonna delete that file
because
I don't need it.
So to delete a single file,
all you'll do is type rm
and then the filename
and if I
list again,
we do not have a file.txt.
Let's create a directory
and I'm gonna create it as administrator
so
sudo mkdir
which means make
directory
and
I'm gonna name it mydir
and we can see here
that my directory has been created.
And we can see the permissions on this,
it's owned by root root.
Now, what this means is it's readable, writeable and executable.
This means that,
anybody else can read and execute it.
So I can change directory into mydir.
This is executing it
so I've just allowed myself to execute
that and
that allows me to go into it.
Now,
let's say
I wanted
to
go back up at directory
and use
let's create a file actually in that directory so I'm gonna type
sudo nano file.txt
actually I gotta put that
in
mydir
and the way we do that again we
specify in the current directory find
mydir
and create it in there
and hit enter.
Now if I ls
mydir,
I see that I have a file in there.
If I type ls -l ./mydir,
I can see that the file in there is also owned
by the root.
Let's make another file.
So I'm gonna run the previous command
and in
in terminal you can hit the up key
and you can keep hitting it and it's gonna go up up up
from previous commands that you've entered.
So I see there's two files in that directory that I want to own.
As we can see right now both files are owned by root because I've created them
using the super user account.
Now,
what we're gonna do here is
a form of the change ownership
binary file
or
command.
And how we're gonna do that is type sudo chown
and we're gonna pass it this argument,
-R
which means
it's recursive.
Every file
in this directory
is going to become
under the owneship
of
nick.
So to give a little bit about this command that we're running
because it might look confusing
because there are multiple parts to it,
we're running it as sudo
because
we currently don't have
permissions to this directory because it's owned in
by the root user and group
and
we have no right access so we can't change it,
so we're running this command as sudo.
chown
stands for change ownership.
That's the program that we're running.
We're passing it this argument -R
to make the command recursive.
If I didn't have this
in this command,
if it looked like this,
this would change the ownership of the directory
to nick:nick
but not the files in it.
So,
capital R is
as an argument there
and then the user in the group that we want to assign ownership to
and then the file
or directory
that we're going to perform that action on.
So when I hit enter,
and then type ls -l, we see now
that I've got ownership of this directory
and if I
type
ls -l
on mydir,
we can see I've also got ownership on all of the files within that directory.
So, to recap
we use
chown
to change ownership of a file.
We use chmod to change the permissions of the file.
Both of these can be recursive
by adding -R to the command.
Then we
define the specifics of the change we're making. So with chmod it's gonna be
755 or 757 or 777, this is just a bad idea
if you're running a server and never make any directories, ownership, 777.
Files are 1 digit less so
666 would be full
modification ability
for anybody
on the file,
we would never do that.
664 means
the owner of the file and the group of the file have read, write and access
and the
public has read access
and 644 means owner has read, write,
group has read
and public has read.
Now, if we're using the
chown command,
it's going to be in the format user:group
and this is going to change the ownership of whatever file we give it
to that.
And then, the last part of each of these two commands
is the file or directory that we want to have this effect on.
So if I type /usr/share
this is going to give my user
all
all the files in this directory are gonna become under
the ownership of my user and my group.
Be careful when you run that because some files
need to owned by root in order to work,
typically you're not gonna be working too much outside of your home directory
but we're gonna get there. There are some files you're gonna need to change
especially when we set up a patchy as the web server
and what not.
So thanks for watching this video, I hope it's been informative
I'll see you guys in the next video.