Chapter 7: Bash Change Dir (cd)

Bash Change Dir (cd) — the cd command, which stands for “Change Directory”.

This is one of the first three commands every beginner learns (along with pwd and ls), because without cd, you’re stuck in one place forever in the terminal!

Think of your computer’s file system like a big multi-story building in Hyderabad:

  • Root (/) = the ground floor / basement (everything starts here)
  • Your home (/home/webliance) = your personal flat on the 5th floor
  • Folders like Documents, Downloads, Projects = rooms inside your flat
  • cd = the elevator / stairs you use to move between floors and rooms

Without cd, you can’t visit other rooms or floors!

Basic Syntax

Bash
  • No argument → go to your home directory
  • With argument → go to that place

Most Common & Useful Ways to Use cd (Practice These Right Now!)

  1. Go Home (your safest, most important place)
Bash

All three do the exact same thing — take you to /home/webliance (or /Users/webliance on macOS).

After typing any of them:

Bash

→ You should see something like /home/webliance

  1. Go up one level (parent directory)
Bash

Example:

Bash

.. = special name for “parent folder”

  1. Go to root (top of the entire system)
Bash

→ Now you’re at the very top — be careful here, don’t delete anything!

  1. Go back to the previous directory (super useful!)
Bash

This jumps to where you were before the last cd.

Example:

Bash

Bash remembers the previous location in a variable called $OLDPWD.

→ cd – also prints the directory it goes to (very helpful).

  1. Go to a specific folder (relative or absolute path)

Relative (from where you are now):

Bash

Absolute (full path from root):

Bash
  1. Multiple levels at once
Bash

Bash creates the path in your mind — no need to cd step-by-step.

Special Tilde (~) Tricks (Bash Magic!)

Tilde ~ is a shortcut for your home.

  • ~ = your home
  • ~/ = same as above (with slash)
  • ~username = someone else’s home (if you have permission)

Examples:

Bash

Advanced tilde (rare but cool):

  • ~+ = current directory (same as $PWD)
  • ~- = previous directory (same as $OLDPWD)
Bash

Quick Reference Table (Memorize This!)

What you want to do Command Example Output / Result
Go to your home cd or cd ~ /home/webliance
Go up one folder cd .. From Documents → home
Go up two folders cd ../.. From src → project root
Go back to previous location cd – Prints and jumps back
Go to root cd / /
Go to specific folder (relative) cd foldername cd Pictures
Go deep relative cd folder/subfolder cd Downloads/wallpapers
Full absolute path cd /path/from/root cd /etc/systemd
Someone else’s home cd ~otheruser cd ~rahul
Current dir (tilde trick) cd ~+ Same place (rarely used)

Common Mistakes & Teacher Warnings

  • No space → wrong: cd.. → correct: cd ..
  • Typo in name → cd Documets → error: No such file or directory
  • Case sensitive → cd documents ≠ cd Documents
  • Permission denied → You can’t cd into folders you don’t have permission for (use ls -ld folder to check)
  • cd inside script → Changes directory only for that script — terminal stays where it was
  • cd – first time in new terminal → sometimes says bash: cd: OLDPWD not set (normal — no previous location yet)

Practice Session Right Now (Do This!)

Bash

See how fast you move? That’s the power of cd!

Got it, boss? Any place confusing? Want to know about pushd / popd (advanced cd stack)? Or how to fix cd to auto-run ls after? Or practice more?

Just say — “Teacher, explain cd with pushd popd” or “more cd tricks” or next command like “mkdir” or “pwd deep dive”.

Keep moving around the terminal — soon you’ll feel like you own the building! 🏢🐧 From Hyderabad! 😄

You may also like...

Leave a Reply

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