DEV Community

Aryan Vaishnani
Aryan Vaishnani

Posted on

Absolute vs Relative Paths

Paths are used to locate files and directories in Linux.

1. Absolute Path

An absolute path starts from the root directory:

/

It shows the complete location of a file or folder.

Example

/home/aryan/projects/app.py

This path works from anywhere in the system.

2. Relative Path

A relative path starts from the current directory.

It does NOT start with /.

Example

Current directory:

/home/aryan

Command:

cd projects

Linux understands:

/home/aryan/projects

Special Symbols

Symbol Meaning
. Current directory
.. Parent directory
~ Home directory

Examples

Current Directory

./script.sh

Parent Directory

cd ..

Home Directory

cd ~

Difference Table

Absolute Path Relative Path
Starts with / Does not start with /
Full location Based on current location
Works everywhere Depends on current directory
Longer Shorter

Real-World Example

Current directory:

/var/log

Relative Path

cd nginx

Absolute Path

cd /var/log/nginx

Both go to same directory.

Easy Trick

  • Absolute Path = Full address
  • Relative Path = Nearby shortcut

Top comments (0)