Introduction

The Linux system is all files and directories. These files and directories can be accessed through paths.

The root directory

Everything is referenced from the root path (represented as slash /). Other separators can be used from the root path and can be accessed through a relative or absolute path.

1. Absolute path

When accessing a file with an absolute path we start from the root / followed by separators to other directories in the middle up to the target file:

Image showing the current directory

Type pwd in your terminal and print the current path. The first slash / represents the root directory.

All users created in Linux are stored in the home directory. The current user as used in the example is nmurgor

The absolute path is the path from the / root to the target file with all child directories. In this case, our absolute path is /home/nmurgor

Suppose one wants to check the contents of the Downloads directory:

nmurgor@nmurgor:~$ ls /home/nmurgor/Downloads

2. Relative path

Accessing a file in a relative path usually involves accessing a file within the parent directory:

nmurgor@nmurgor:~$ cd Downloads/
# switches to Downloads child directory
nmurgor@nmurgor:~/Downloads$

The Downloads/ path is relative(and a child of) nmurgor/ path and exists inside nmurgor/


Found this article helpful? You may follow me on Twitter where I tweet about interesting topics on software development.