📂 Command: cd (Change Directory)
The cd command is your primary tool for moving around the Linux filesystem. If the terminal is your vehicle, cd is the steering wheel.
1. The "Why"
In a graphical interface, you click on folders to open them. In the terminal, you "enter" a folder using cd. Without it, you are stuck in one spot, unable to access your projects, downloads, or system configuration files.
2. Basic Syntax
cd [DESTINATION]
- Destination can be a folder name, a full path, or a special shortcut character.
3. Essential Shortcuts
Bash provides several "magic" characters that make navigating much faster than typing full paths:
| Shortcut | Description |
|---|---|
cd .. |
Up one level: Moves you to the parent directory. |
cd ~ |
Home: Takes you straight to your user's home folder (/home/username). |
cd - |
Back: Takes you to the previous directory you were in (like a "back" button). |
cd / |
Root: Takes you to the very base of the entire Linux system. |
4. Practical Examples
A. Moving into a Folder
To go into your "Documents" folder from your home directory:
cd Documents
B. Jumping Across the System (Absolute Paths)
If you are in your home folder and want to jump straight to the system configuration folder:
cd /etc/X11
(Note: Starting with a / tells Linux to start looking from the Root, not from where you are currently standing.)
C. Climbing the Tree
If you are deep in a folder structure (e.g., ~/projects/android/app/src) and want to go back to the android folder:
cd ../..
D. Handling Spaces in Names
If a folder has a space in its name, you must use quotes or a backslash:
cd "My Projects"
# OR
cd My\ Projects
5. Pro-Tips
- The Power of Tab: Never type a full folder name. Type the first two letters and press Tab. Bash will auto-complete the name for you. This prevents typos!
- Know Where You Are: If you get lost after using
cdtoo many times, typepwd(Print Working Directory) to see your exact location. - CD into Root for Configs: Since you use Linux, you’ll often find yourself doing
cd /etcto tweak system settings orcd /home/[user]/.configto edit your Hyprland or Waybar files.
6. Summary Reference
| Goal | Command |
|---|---|
| Go home | cd or cd ~ |
| Move up one folder | cd .. |
| Move up two folders | cd ../.. |
| Return to last folder | cd - |
| Go to specific path | cd /path/to/folder |