For school, I have to switch between my top level directory which is git-basics-lab-online-web-sp-000 back to the sub directory I made which is called my-repository. I was switching back and forth no problem using {cd} but when I tried to switch back to my-repository using
cd my-repository
my terminal is now saying
bash: cd: my-repository: No such file or directory
what did I do wrong?! How come it worked before but now it's giving me this message?
Perhaps we are missing more information. That is, if you moved correctly from one directory to another, there is no reason why it should disappear just like that.
Besides cd
, there are other commands that will help you to know which directory you are in, and where you can go. I summarize them below:
Show the full path to the current directory:
pwd
List files and folders (except hidden ones):
ls
Enter the dir
directory (assuming it exists where we are):
cd dir
Exit dir
(see edit):
cd ..
Obviously each command has a number of options that increase its functionality. You can always access them with the man
command (for example, man cd
will show you the cd
command help).
That is, once the terminal showed you the error you mention, you can run ls
to verify, for example, if you typed the folder name wrong. Then you can also try pwd
to confirm that you are where you think you are. And finally you can move with cd
to where you think you are.
EDIT: As suggested by Roadowl, cd -
and cd ..
are not strictly the same thing (in the example I assume we go one directory at a time).
I will try to illustrate this with an example to show the difference.
Suppose we have the dirc
folder inside dirb
and this, in turn, inside dira
( dira/dirb/dirc
). Let us also suppose that we are in dira
. To enter directly to dirc
we would have to execute cd dirb/dirc
. And this is where the difference is illustrated:
cd ..
we are going to be positioned in dirb
.cd -
we will go back to the dira
directory we were in before running the command.