Absolute and relative file paths

Under Linux®, file paths are used to specify the location of files and directories in the file system. There are two types of paths: absolute paths and relative paths.

Absolute paths

An absolute path specifies the complete location of a file or directory from the root directory /. It always begins with a slash / and provides the complete path to the destination.

Examples of absolute paths:

Regardless of where you are currently located in the file system, an absolute path always points to the same location.

Relative paths

A relative path specifies the location of a file or directory relative to your current working directory. It does not begin with a slash /.

Special directory symbols:

Examples of relative paths:

If your current directory is /home/Administrator:

Important commands for navigating the file system.

Command

Description

pwd

Use pwd to view your current directory.

cd /etc

Use cd /etc to change to the /etc directory with an absolute path.

cd ..

Use cd .. to move up one level.

ls -l

Execute ls -l to list the contents of the current directory in long format.

cd ~

Use cd ~ to return to your home directory.

ls -a

Run ls -a to list all files including hidden files.

ls ./.ssh

Use ls ./.ssh to navigate with a relative path.

ls /usr/bin

Try ls /usr/bin to list files with an absolute path.

ls ../

Try ls ../ to list the higher-level, higher-order directory with a relative path.