06: The root directory
Let’s change directory to the root directory, and then into our home directory
learner@:inner$ cd /
learner@:/$ cd home
learner@:home$ cd learner learner@:~$
In this case, we may as well have just changed directory in one go:
cd /home/learner/
The leading /
is incredibly important. The following two commands are very different:
cd /home/learner/ cd home/learner/
The first command says go the learner
directory that is beneath the home
directory that is at the top level (the root) of the file system. There can only be one /home/learner
directory on any Unix system.
The second command says go to the learner
directory that is beneath the home
directory that is located wherever I am right now. There can potentially be many home/learner
directories on a Unix system (though this is unlikely).
The second command run after the first one should give
bash: cd: home/learner: No such file or directory
because it searches directory learner
in directory home
in the current directory, which is /home/learner
. So, it tries to change to the direcotry /home/learner/home/learner
, which does not exist. Hence the message.
Learn and understand the difference between these two commands.