Instructor: Cannot CD or Change Directory
into a 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 are going to troubleshoot
today in this lecture.
So there are 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 a few things you need to check.
A few things to keep in mind
and those are the things I wanted to list today.
So 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 are not,
you actually have a incorrect spelling of the directory
you finger type,
you fat fingered it
or it's 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
if the direct do not exist.
So let me log into 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 /root directory.
Here in this directory
I will create a new directory
and I'll call it seinfeld, 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, huh?
Why am I getting this?
No such file a 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 a uppercase S,
whereas the the 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 we CD into this system
or into the directory.
Now next thing is Absolute versus Relative path.
When you're trying 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 the 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 the seinfeld directory.
I'll hit Enter.
There's nothing in that directory because it's empty.
And 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'll 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 subdirectory 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 says,
"No such file directory."
Now you are back to the equation one
where we were talked about directory does not exist.
You need to relax,
you need to see where that directory was created.
Anyway, so make sure you 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 when I do PWD
you'll see I am in slash directory.
I could go straight to jerry directory
the way I did it before
which is CD /root/seinfeld and /jerry
and I'll go straight into that directory.
But if you cannot get in
and you're trying to troubleshoot
where that directory exists,
then I will 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'll 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 it 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 -l.
And I do see that,
there is a directory called seinfeld.
I wanted to CD into this directory.
But many times the mistakes that people make,
is they do CD /seinfeld.
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 gonna specify slash,
then the system is gonna 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.
So 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 have not,
if you do not have quite
a bit understanding of permissions, that is fine.
I'm here to help you.
So I'm gonna 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.
Second bit is about the write
and the third one is about execute.
Same way it goes for the, sorry,
the first part that I just explained you
is about the you.
The second is for the group.
The first one is you, meaning is yourself
that you are the owner of that directory.
Now don't confuse this U with the last O
because a lot of people confuse you as user
with O as the owner.
Now O, it 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 or directly that we create.
So let's go into our machine
and you'll see here I'm gonna 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 gonna work.
Then you're gonna see is read write and execute,
these three bits.
It means the user who is 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,
whichever whoever the user you are,
you should have executable permissions
to CD into the directory.
Sometime 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 gonna run ls -l, is gonna 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 -x.
This is for everybody else meaning not,
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 the permission.
So if I'm going to take out the permission
of others of seinfeld,
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 the little X is gone.
Now when if I become myself, which is iafzal.
Now if I try to go to root,
permission denied.
Oh 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.
Where is root?
Oh 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.
So this time I'm going to give permission
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 gonna give it back the executable.
By the way, this is the command change mod.
I am hoping, and I'm assuming everybody knows.
This is the command to assign
or remove the permission of a file or a 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?
Change mod 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'll 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,
see right here no one
other than root or its group
is allowed to come in, create or read the content.
That's what you're getting the permission denied
or you're seeing 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,
where is root?
This is root.
If you notice, we have given the permission to come in.
Anybody could come into root,
but they cannot view the content
because they don't have a 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 a 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 elaine.
So if I try to do cd elaine, 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 /root,
no matter how many permissions you have
after the /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 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 directories.
Meaning you create a file or directory
let's say mkdir
and I will make a directory .simpsons
and I do ls -ltr.
And you notice there is no simpsons
but someone tells you,
"Hey go to this directory
and they actually miss out the dot
because the dot something that makes it hidden.
So you will have to do ls -la
to show all hidden files.
And in the hidden files you'll see
there's a simpsons directory.
Now you could do into CD .simpsons
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'll be able to resolve your issue.