How do I navigate between directories in terminal?
Solution 1:
The filesystem is GNU/Linux is like a tree, except that the root is on top. :-) So you have structure like:
/
bin/
home/
sharon/
Documents/
Downloads/
fileA.txt
fileB.jpg
usr/
var/
If you want to move inside the tree, one option is to use relative paths. If you are in /home/sharon
, then typing cd Downloads
will work, because Downloads is an immediate child of your current directory. If you are in the subfolder Documents
and want to change directory (cd
) to Downloads
, you have to go up (..
) and then to Downloads
. So the correct command would be cd ../Downloads
.
You could also enter an absolute path. So the Downloads
folder is a subfolder of sharon
which is a subfolder of home
which is … (you get the idea :-))
So you can also enter cd /home/sharon/Downloads
wherever you are in the filesystem.
~
always refers to the home directory of the current user (/home/sharon
in your case). If you entercd ~/Downloads
you'll land in yourDownloads
folder..
refers to the current directory, socd ./Downloads
is roughly equivalent tocd Downloads
...
means "parent directory"./
at the beginning of file path refers to the root directory.
The next nice thing is tab expansion. If you enter cd ~/Dow
Tab (last is pressing Tabulator key), the bash automatically expands it to cd ~/Downloads
.
As the others said GNU/Linux is case sensitive. So it makes a difference if you enter Home
, hOme
or home
. Furthermore I hope that you see now that there is a difference between /home
and home
. The first is adressed absolute while the last is relative to your current directory.
Solution 2:
sharon@sharon:~$ cd Home
bash: cd: Home: No such file or directory
The little cedilla ~ indicates you are already in your /home/sharon directory. When you ask for 'cd Home' the terminal looks for /home/sharon/Home. There is none.
sharon@sharon:~$ cd /Home
bash: cd: /Home: No such file or directory
Now you are asking, given the leading slash, to go to a directory above the current location; that is /home/Home. There is none.
sharon@sharon:~$ cd Documents
sharon@sharon:~/Documents$
Success!
sharon@sharon:~/Documents$ cd /Downloads
bash: cd: /Downloads: No such file or directory
I'm not too sure where exactly this is. If you want to change from /home/sharon/Documents to /home/sharon/Downloads, please try:
cd ~/Downloads
If you want to go directly to your home directory, that is /home/sharon, simply do:
cd
Also you can go Step back with
cd ..
And you can print the directory you are working in with (print working directory)
pwd