Linux cd Command
The cd command is used to move between directories in Linux.
It is one of the most frequently used commands because Linux systems contain many folders and files, and navigation is impossible without cd.
What does cd mean?
cd stands for:
Change Directory
Syntax
cd [DIRECTORY]
Basic Usage
Suppose your current location is:
/home/aayan
Move into Documents:
cd Documents
Check:
pwd
Output:
/home/aayan/Documents
Current Directory Structure
/home/aayan
├── Documents
├── Downloads
├── Projects
└── Desktop
Going to an Absolute Path
Absolute paths always start from:
/
Example:
cd /etc
Check:
pwd
Output:
/etc
Another example:
cd /var/log
Output:
/var/log
Relative Paths
Relative paths start from your current directory.
Current location:
/home/aayan
Move:
cd Projects
Linux automatically interprets:
/home/aayan/Projects
Command Shortcuts
cd
No argument.
Moves to home directory.
cd
Output:
/home/aayan
cd ~
Also moves to home directory.
cd ~
cd ..
Move one directory backward.
Example:
Current:
/home/aayan/Documents
Command:
cd ..
Result:
/home/aayan
cd ../..
Move two directories back.
Current:
/home/aayan/Projects/Web
Command:
cd ../..
Result:
/home/aayan
cd -
Move back to previous directory.
Example:
cd /etc
cd /var/log
cd -
Output:
/etc
Another:
cd -
Output:
/var/log
This toggles between directories.
cd /
Move to Linux root directory.
cd /
Output:
/
cd .
Current directory.
Nothing changes.
cd .
Using Tab Completion
Suppose:
Documents
Downloads
Desktop
Type:
cd Doc
Press:
TAB
Linux automatically completes:
cd Documents
Directory Names with Spaces
Wrong:
cd My Folder
Correct:
cd "My Folder"
or:
cd My\ Folder
Practical Examples
Example 1
Move into Downloads:
cd Downloads
Example 2
Move into root:
cd /
Example 3
Move into logs:
cd /var/log
Example 4
Return home:
cd ~
Example 5
Go back:
cd ..
Real Server Examples
PocketMine-MP Server
Move into server folder:
cd /home/minecraft/server
Plugins Folder
cd plugins
Worlds Folder
cd worlds
Logs Folder
cd logs
Website Hosting
cd /var/www/html
PHP Configuration
cd /etc/php
Nginx Configuration
cd /etc/nginx
Ethical Hacking Examples
Wordlists:
cd /usr/share/wordlists
Tools:
cd /opt
Logs:
cd /var/log
Common Mistakes
Wrong Directory Name
cd document
Output:
No such file or directory
Linux is case-sensitive.
Correct:
cd Documents
Forgetting Spaces
Wrong:
cd/home
Correct:
cd /home
Not Knowing Current Location
Always use:
pwd
before navigating.
Flags / Special Arguments Summary
| Command | Description |
|---|---|
cd | Go home |
cd ~ | Home directory |
cd .. | Parent directory |
cd ../.. | Two directories back |
cd - | Previous directory |
cd / | Root directory |
cd . | Current directory |
Interview Questions
What does cd stand for?
Change Directory
Difference between absolute and relative paths?
Absolute:
/home/aayan/Documents
Relative:
Documents
What does cd - do?
Returns to previous directory.
What does ~ represent?
User's home directory.
Why is cd important?
Because Linux systems contain thousands of directories and navigation depends on it.
Exercises
Exercise 1
Move to:
/etc
Exercise 2
Move back to home.
Exercise 3
Create:
Projects/Web/PHP
Navigate there.
Exercise 4
Move back two directories.
Exercise 5
Practice:
cd -
multiple times.
Mini Lab
Create:
mkdir -p LinuxLab/Projects/PHP
mkdir -p LinuxLab/Projects/Python
mkdir -p LinuxLab/Backups
Practice:
cd LinuxLab
cd Projects
cd PHP
cd ..
cd -
pwd
Command Summary
| Command | Purpose |
|---|---|
cd folder | Enter folder |
cd .. | Parent directory |
cd - | Previous directory |
cd ~ | Home directory |
cd / | Root filesystem |
Key Takeaways
✅ cd means Change Directory.
✅ Used to navigate Linux filesystem.
✅ Supports absolute and relative paths.
✅ .., ., ~, and - are essential shortcuts.
✅ One of the most important Linux commands.
Next Chapter
➡ Linux mkdir Command
Learn how to create directories in Linux.