Userbie

Absolute and Relative Paths

You should be aware of absolute and relative paths in the file tree. When you type a path starting with a slash (/), then the root of the file tree is assumed. If you don’t start your path with a slash, then the current directory is the assumed starting point.

The screenshot below first shows the current directory /home/paul. From within this directory, you have to type cd /home instead of cd home to go to the /home directory.

paul@debian8$ pwd
/home/paul
paul@debian8$ cd home
bash: cd: home: No such file or directory
paul@debian8$ cd /home
paul@debian8$ pwd
/home

When inside /home, you have to type cd paul instead of cd /paul to enter the subdirectory paul of the current directory /home.

paul@debian8$ pwd
/home
paul@debian8$ cd /paul
bash: cd: /paul: No such file or directory
paul@debian8$ cd paul
paul@debian8$ pwd
/home/paul

In case your current directory is the root directory /, then both cd /home and cd home will get you in the /home directory.

paul@debian8$ pwd
/
paul@debian8$ cd home
paul@debian8$ pwd
/home
paul@debian8$ cd /
paul@debian8$ cd /home 
paul@debian8$ pwd
/home

This was the last screenshot with pwd statements. From now on, the current directory will often be displayed in the prompt. Later in this book we will explain how the shell variable $PS1 can be configured to show this.