[No audio]
cd or change directory into our directory.
Meaning, when you're trying to run the command
cd and you're trying to go to another
directory that's where you are having an issue
or you're getting an error message.
So why is that?
And that is what we're going
to troubleshoot today in this lecture.
So there are a few steps that we could
take to actually isolate these type of issues.
And when you cannot get into a directory, of
course there are few things you need to check,
a few things to keep in mind,
and those are the things I wanted to list today.
First thing first.
Directory does not exist.
It's just that simple.
So you are trying to cd into a
directory or a folder, but you cannot.
And the error message that you're
getting is directory does not exist.
Try to read that message, the output, the
error, what it is saying to you.
It's saying the directory does not exist.
So either you actually have an incorrect spelling
of the directory, you finger typed, you fat fingered
it or it simply just does not exist.
Or somehow it does not exist in
the right directory where you are.
So first thing is how we could
tell that the directory not exist.
So let me log in to my machine.
I have a machine right here.
Now I am logged in as myself root sorry.
I am in which directory? I do pwd.
I am in slash root directory. Here,
in this directory I will create a
new directory, and I'll call it seinfeld.
[No audio]
Okay. So now when I do ls -ltr, I will see the directory.
It is created with the name seinfeld.
Now if I'm trying to cd into that
directory Seinfeld, why am I getting this?
No such file or directory.
That is the most common issue
people see and they get confused. Oh my God. Why?
Where did the directory go?
But you need to understand, relax
and see what the problem is.
If you notice, I typed uppercase S, whereas the
directory that I created is with lowercase s.
Now in Linux or Unix environment,
uppercase and lowercase matters a lot.
So keep that in mind.
So the Seinfeld with uppercase
directory does not exist.
That is why you are having issues with logging
in or cding into the system, into the directory.
Now, next thing is absolute versus relative path.
When you try to cd into a directory many
times you have a path given and you put
the path in but it doesn't work.
Or you are trying to cd into through a relative path.
You need to know where that folder is.
Let's get into my Linux machine again.
Let's clear the screen.
So we do have a directory
that we created which is seinfeld.
Now I want to cd into this seinfeld directory.
I'll hit enter.
There's nothing in that directory because
it's empty. In the seinfeld directory,
I will create another directory called jerry,
and I'll create another directory called kramer.
So now inside of seinfeld, I
have two directories jerry and kramer.
And if I go into jerry directory and
I'll do pwd you will see the entire
path of this directory is root/seinfeld/jerry.
So that is one of the things that you will
experience when you try to cd into a directory,
when you are missing a subfolder or sub
directory in the absolute path. This entire path,
if you're trying to cd into
this entire path, it will work.
It is going in.
But if you are missing, let's say if you're
missing one directory, let's say root and jerry.
You know that you created jerry but you just
couldn't keep track of where that directory go.
You hit enter and say, No such file or directory.
Now you are back to the equation
one where we were talking
about directory does not exist.
You need to relax.
You need to see where that directory was created.
Anyway, so make sure your absolute path is
correct. When you come to relative path,
relative path is when you cd in
let's say if I'm in cd slash, and then I
do pwd, you will see I am in slash directory.
I could go straight to jerry directory the way I
did it before with a cd /root/seinfeld/jerry,
and I will go straight into the directory.
But if you cannot get in and you're trying to
troubleshoot where that directory exists then I would recommend you
that you go one step at a time.
Like you are climbing up the stairs.
Don't just try to jump three stairs up.
Go one step at a time.
So for that you will do cd /root.
Now here, you need to do ls -l and see if there
is a folder or a directory in the listing that says jerry.
Does it? No right.
So it means it's not there.
So try to see where that directory is.
Then you'll go into another folder
that is called seinfeld.
You are in the seinfeld.
Do ls -l again.
And now there it is, the directory called
jerry or kramer wherever you want to go.
And that's how you are ending
up with the directory jerry.
Another common mistake people make which is, going
through the relative path but specifying absolute path.
What does it mean? Let's check.
So if I'm cd into slash, this is my main
primary, the root very first directory of the system.
Now I wanted to go into /root directory.
Okay, I am in /root directory.
It says I am in /root and I'll do ls minus
l, and I do see that there is a directory called seinfeld.
I try to cd into this directory.
But many times the mistakes that people
make is they do cd /seinfeld.
[No audio]
And when you hit enter, you get the
same message, No such file or directory.
Why is that?
Because you are telling Linux operating system that this
seinfeld is actually located at the root level,
meaning at this level. It is not located at
the root level, it is located under /root directory.
So if you're going to specify slash then the
system is going to think that you are trying
to find that seinfeld directory in this /root.
And when you do ls -l,
you'll see there is no seinfeld.
Make sure you need to know where you
are using slash and where you are not.
So that is why that's a common mistake people
make when they do absolute path versus relative path.
Next one we have permissions.
Of course this is also very common when you
are trying to cd into a directory and you
cannot because you do not have permissions.
Let me explain you permissions first.
If you do not have quite a bit
of understanding of permissions that is fine.
I'm here to help you.
So I'm going to explain to
you the permission part in detail.
The permission of a file or a
directory is divided into three different groups.
One that you see on the left
hand side which has four bits.
By the way, these dashes are referred as bits.
Then this is a section which is divided for
group, and this is a section for other.
Now the first bit is actually the one
that defines what type of file it is.
Whether it is a file, it is a directory, it's
a link, it's a socket file, anything, any type of
file or what's the function of a file.
It's all defined with the first attribute.
If you see a d here on the
first one then it means it's a directory.
Then only then you could go in.
Second bit is about read.
So if you have read permission on
the directory then can you get in?
No read permission on a directory means
you could still get in if you
have executable but you cannot write anything.
So this is the read.
3rd bit is about the write,
and the third one is about execute.
Same way it goes for the first part that
I just explained you is about the u.
The second is for the group.
The first one is u, meaning yourself, that
you are the owner of that directory.
Now don't confuse this you with the last o because a lot
of people confuse u as user with o as the owner.
Now o stands for others. Anyway,
so second set of permissions
again read, write, execute.
Then the third one is for
everyone else read, write, execute.
These are the permissions about every
file directory that we create.
So let's go into our machine and you will
see here I'm going to go into /root, ls -ltr
to see my seinfeld directory.
And you notice in the seinfeld directory we have these permissions.
If you do not have d in front of
a directory it means it's not a directory.
No matter how many times you try to cd into it.
It's not going to work.
Then you're going to see is read,
write, and execute, these three bits.
It means the user whose root can
have read and write and execute permission.
When you say read, it means the user
can read the content inside of the directory.
When you have write, it means the user can
actually write or create files inside of this folder.
And when you have X, it means the
user can actually go into the directory.
Now this is very important.
You need to know this.
If you do not have this little bit right here
execute, then you cannot cd into a directory.
So make sure whichever group you are, whoever
the user you are, you should have executable
permissions to cd into the directory.
Sometimes people confuse that with the read permission.
Read and execute is not the same.
Read allows you to cd into a directory whereas
this r allows you to read the content.
If you do not have r then
you could still cd into a directory.
But when you're going to run ls -l,
it's going to say you don't have
permission to view the content of the directory.
So you got it.
Hopefully you do.
Then the second step is from here r dash x.
This is for everybody else, meaning not, sorry, everybody.
This is for group.
Right now the user is root.
The group is root.
These are the two column who owns and
who actually which group they are in.
So the group permissions, you
could actually read the content.
You could cd into the directory but
you cannot create any file or directory.
The last one is the same for everyone else.
You could read the content and
you could cd into the directory.
But you cannot create anything in it.
So make sure you do not you have that permission.
So if I'm going to take out the permission of others,
of seinfeld,
[No audio]
so now what I'm saying is only root and
its group can get into seinfeld, everybody else cannot.
And you do ls -ltr you'll
see that little x is gone.
Now if I become myself, which is iafzal.
Now if I try to go to root, Permission denied.
Or even root doesn't have permission for me to come in.
So let me go to slash and
I'll do ls -ltr on root.
[No audio]
Where's root? Right here.
You see, at the root level I'm not allowed to come in.
Forget the seinfeld level.
So make sure this executable exists.
So let's go back as root.
[No audio]
So this time I'm going to give permission
[No audio]
for everyone to have, to cd into root.
Now I'm in. Now,
this one has a directory seinfeld,
and I have taken out executable.
Now I'm going to give it back the executable.
[No audio]
By the way, this is the command chmod.
I am hoping, and I'm assuming everybody knows
this is the command to assign or remove
the permission of a file or directory.
So now I'll do ls -ltr, and you
see the permissions are granted to cd into it.
I still cannot create any file.
What if I remove r, chmod, others, remove r, seinfeld.
So now when you do ls -ltr, you
notice I do not have read permission.
So now if I go into the seinfeld directory and you
see I could view the content of jerry and kramer because
I'm root, what if I become, iafzal, and now I
go to cd into /root and I do ls -l.
I cannot view the contents of root. Why? Because
at the root level right here, right here no
one other than root or it's group is allowed
to come in, create or read the content.
That's why you're getting the permission denied.
Or you're saying cannot open directory.
You could still cd into it.
Why you could cd into it?
Because we have given the executable
if you remember, right here.
Let's go cd slash,
[No audio]
where is root?
[No audio]
This is root.
If you notice we have given the permission to come in.
Anybody could come in to root but
they cannot view the content because they
don't have read permissions. Anyway,
so that's another reason why you
cannot cd into the directory.
Next reason, file type. This is
I already talked about it.
If a file or directory does not have a d
in front of it then it's not a file.
Sorry, then it's not a directory.
So if I am in my home directory, /home/iafzal,
and I create a file called touch eliane.
So if I try to do cd eliane, what will happen?
It will say it's not a directory. Why?
Because when you do ls -ltr, you'll see
there is no d in front of it.
So that's the file type I'm talking about.
Make sure the file type is correct.
The next one is parent directory permission.
We have already covered that.
When you do not have a correct permissions, let's say
on the slash root, no matter how many permissions you have
after the slash root, it does not matter.
It's just the front main door is locked
so you cannot go to the bedroom door.
So that's why I make sure the
parent directory has a proper permission.
And the last one is the hidden directories.
Many times people also make a
mistake of a hidden directory.
Meaning you create a file or directory.
Let's say mkdir and I will make directory .simpsons, and I
do ls -ltr, and you notice there is no simpson.
But someone tells you hey, go to this directory
and they actually miss out the dot because the
dot is something that makes it hidden.
So you will have to do ls
minus la to show all hidden files.
And in the hidden file you'll
see there's a simpson directory.
Now you could do into cd .simpson
and then now you are in.
So make sure the directory you're trying
to come into is not hidden.
So these are the few pointers I
want you to keep in mind.
If you go through every step of these
troubleshooting, steps I'm pretty sure you will be
able to resolve of your issue.
[No audio]