Linux

The cd Command in Linux — Complete Guide with Examples

The cd command — short for change directory — is the most fundamental navigation command in Linux. Every Linux user, from beginners to senior sysadmins, uses it dozens of times per session. This guide covers every variant of cd you will need in real-world Linux work.

Basic Usage — cd to a Directory

$ cd /path/to/directory

After running cd, verify your current location with pwd (print working directory):

$ pwd

cd with Absolute Paths

An absolute path starts from the filesystem root / and specifies the complete path to the destination:

$ cd /var/log/nginx
$ cd /home/irfan/projects
$ cd /etc/nginx/sites-available

Absolute paths work from any directory — they always lead to the same place regardless of where you currently are.

cd with Relative Paths

A relative path is relative to your current directory. If you are in /home/irfan and want to go to /home/irfan/projects/myapp:

$ cd projects/myapp

No leading / means the path starts from your current location.

Go to Your Home Directory

Three equivalent ways to return to your home directory (/home/username):

$ cd
$ cd ~
$ cd $HOME

All three do the same thing. cd with no arguments is the fastest to type.

Go Up One Directory — cd ..

Two dots (..) represents the parent directory:

$ cd ..            # Up one level
$ cd ../..         # Up two levels
$ cd ../../etc     # Up two levels, then into etc/

Go to the Previous Directory — cd –

The hyphen shortcut is one of the most useful cd tricks:

$ cd /var/log
$ cd /etc/nginx
$ cd -             # Returns to /var/log

cd - toggles between your current and previous directory. It is invaluable when you need to move back and forth between two locations repeatedly — a log directory and a config directory, for example.

Navigate with Tab Completion

Start typing a directory name and press Tab to autocomplete:

$ cd /var/lo[Tab]         # Completes to /var/log/
$ cd /etc/ngi[Tab]        # Completes to /etc/nginx/

If multiple directories match, press Tab twice to see all options.

Directories with Spaces — Quoting

If a directory name contains spaces, wrap it in quotes:

$ cd "My Documents"
$ cd 'My Documents'
$ cd My\ Documents       # Backslash escaping also works

cd Quick Reference

Command What it does
cd /path Navigate to absolute path
cd dirname Navigate to relative path
cd Go to home directory
cd ~ Go to home directory
cd .. Go up one directory
cd ../.. Go up two directories
cd – Toggle to previous directory

Muhammad Irfan Aslam

Muhammad Irfan Aslam is an IT professional and technology writer based in Riyadh, Saudi Arabia. With expertise in IT infrastructure, cybersecurity, and cloud solutions, he helps Saudi businesses navigate digital transformation aligned with Vision 2030. He covers enterprise IT services, managed support, and emerging technologies for the GCC region.

Leave a Reply

Your email address will not be published. Required fields are marked *

Saudi Arabia’s IT intelligence hub — cybersecurity, cloud, infrastructure & digital transformation for Vision 2030 businesses.

Riyadh, Kingdom of Saudi Arabia
Sun–Thu  9:00 AM – 6:00 PM AST

Why Visit To Me

Google News publisher
Riyadh-based IT experts
Vision 2030 aligned
NCA compliance coverage
Arabic & English content
Free IT Consultation →
© 2026 Visit To Me · IT HUB · Riyadh, Kingdom of Saudi Arabia · All rights reserved.
💼
Visit Pro
AI Sales Assistant · Visit To Me
Powered by Claude AI · Visit To Me