Chapter 8: Bash Print Dir (pwd)
Bash Print Dir (pwd), which means the pwd command!
pwd stands for Print Working Directory.
It’s one of the first three golden commands every beginner should know by heart (along with ls and cd).
Why? Because the terminal is like a dark room with no windows — you have no idea where you are unless you ask! pwd is you turning on the light and saying: “Computer, exactly which folder am I standing in right now?”
Without pwd, you can get lost very quickly — especially when you’re deep inside folders or jumping around with cd.
Let me explain it like we’re sitting together in Hyderabad, step-by-step, with real examples, what the output really means, and all the useful tricks.
1. Basic Usage — Just type pwd
Open your terminal right now and type:
|
0 1 2 3 4 5 6 |
pwd |
Typical output (yours will be similar):
|
0 1 2 3 4 5 6 |
/home/webliance |
or maybe
|
0 1 2 3 4 5 6 |
/home/webliance/projects/bash_tutorial/session6 |
or on macOS:
|
0 1 2 3 4 5 6 |
/Users/webliance/Desktop/learning |
or in Git Bash on Windows:
|
0 1 2 3 4 5 6 |
/c/Users/webliance/Documents |
→ This full path is your current working directory — where any command you type (like ls, touch, mkdir, rm) will happen right now.
2. What the Output Actually Means (Anatomy of a Path)
Let’s break down a real example:
|
0 1 2 3 4 5 6 |
/home/webliance/projects/2026/bash_class/day3 |
| Part | Meaning | Nickname / Explanation |
|---|---|---|
| / | Root directory | The very top — everything starts here |
| home | Main folder for all user homes | Usually contains one folder per user |
| webliance | Your username | Your personal apartment / home |
| projects | A folder you created | Inside your home |
| 2026 | Another folder | Maybe yearly organization |
| bash_class | Folder for our lessons | Where we are practicing |
| day3 | Current deepest folder | Where your commands are acting right now |
So when you see:
|
0 1 2 3 4 5 6 |
/home/webliance/projects/2026/bash_class/day3 |
Bash is telling you: “You are currently inside the day3 folder, which is inside bash_class, which is inside 2026, which is inside projects, which is inside your home folder webliance, which is inside the main home folder, which is at the root /.”
3. Most Useful & Common Ways People Use pwd
| Situation | Command you type | Why it’s helpful |
|---|---|---|
| Quick “where am I?” | pwd | Always know your location |
| After many cd jumps | pwd | Confirm you didn’t get lost |
| Before running dangerous command | pwd | Make sure you’re not in / or /etc ! |
| Copy-paste current path to someone | pwd | “Hey, my files are here: [paste output]” |
| Inside a script | echo “Running in: $(pwd)” | Log where the script is executing |
| Compare before & after | pwd → cd .. → pwd | See how location changed |
4. pwd Options (There are only a few — but useful!)
|
0 1 2 3 4 5 6 |
pwd --help |
Shows:
- -L → logical path (follows symbolic links — most common)
- -P → physical path (resolves all symlinks to real location)
Most people never need options — plain pwd is almost always fine.
Example with symbolic links (advanced but good to know):
|
0 1 2 3 4 5 6 7 8 9 |
ln -s ~/projects/myapp ~/shortcut_to_app # create symlink cd ~/shortcut_to_app pwd # → /home/webliance/shortcut_to_app (logical) pwd -P # → /home/webliance/projects/myapp (physical/real path) |
→ -P shows the true location behind any shortcuts/links.
5. pwd in Real Scripts (Very Common Pattern)
Many good scripts start like this:
|
0 1 2 3 4 5 6 7 8 9 10 11 12 |
#!/bin/bash echo "Script started in directory:" pwd echo "Today's date: $(date)" echo "Working on files here now..." # rest of script... |
So when you run ./myscript.sh, you immediately see where it’s running.
6. Quick Practice Session (Do This Right Now!)
|
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# Start from home cd ~ pwd # should show /home/webliance mkdir -p practice/level1/level2/deep cd practice/level1/level2/deep pwd # long path now! cd ../../../ # go up 4 levels (count the ../ ) pwd # back near home cd /etc pwd # /etc cd - pwd # back to previous (deep folder or wherever you were) cd ~ pwd # home sweet home |
See how pwd is like your GPS in the terminal?
7. Teacher’s Golden Rules & Warnings
- Always check pwd before:
- rm -rf something (very dangerous!)
- git init or git clone
- Creating lots of files/folders
- pwd is read-only — it never changes anything, just shows info
- There is no undo for wrong cd — but cd – helps go back quickly
- In some very old systems or minimal containers → pwd might not be available (rare in 2026)
Summary Table – pwd at a Glance
| Question | Answer / Command |
|---|---|
| What does pwd stand for? | Print Working Directory |
| Simplest way to use? | Just type pwd |
| Shows what? | Full absolute path to current folder |
| Most useful before? | Any command that creates/deletes |
| With symbolic links? | pwd -P for real path |
| In script? | echo “Location: $(pwd)” |
| Alternative ways to see path? | echo $PWD (same thing, variable) |
Got it, boss? pwd is boring but lifesaving — use it like breathing in the terminal!
Any confusion? Want to see pwd + ls together in practice? Or next command like “mkdir deep dive” or “how $PWD variable works”?
Tell me — teacher is ready! Keep typing, you’re getting faster every day! 🐧🗺️ From Hyderabad! 😄
