Bash ‘pwd’: Your ‘You Are Here’ Map in the Terminal Before you can run, you need to know where you’re standing. This is Day 4 of the 1-Month Bash Mastery Plan.


👋 Hey everyone,

When you first open a terminal, what do you feel? I remember what I felt: nothing. It wasn’t a “place.” It was a void. Just a black screen, a blinking cursor, and a $ prompt. It felt abstract, disconnected, and deeply intimidating.

In a graphical world (like Windows, macOS, or even a Linux desktop), you always have a sense of place. You’re “in” a folder. You can “see” the folder window. You can see the path in the address bar. You have a “you are here” sign at all times.

The terminal, I thought, had stripped that away. I felt like I was floating in space, blindfolded, and expected to just know where I was. How could I “list files” if I didn’t know which files? How could I “open a file” if I didn’t know where it was?

This feeling of being lost is the first great filter that pushes people away from the command line. They don’t know how to “see.”

Today, we learn how to see. We learn the very first command in the “navigational triad” (the three commands that let you move):

  1. pwd: Where am I?
  2. ls: What’s around me?
  3. cd: How do I move?

You must learn them in that order. And today, we’re mastering the anchor. We’re mastering pwd, which stands for Print Working Directory.


My Goal This Week 🎯

My goal for this post isn’t just to show you the pwd command. That would take one sentence.

My goal is to convince you to build a mental model of the file system and to use pwd as your constant, unwavering anchor. I want to shift your thinking from “typing commands into a void” to “standing in a specific room in a giant digital building.”

pwd isn’t just a command. It’s your GPS. It’s your “You Are Here” map. And once you have it, you’re no longer lost.


The Process & The Code 👨‍💻

Let’s just get it over with. Open your terminal and type this:

pwd

Press Enter. Your computer will respond with something like this:

/home/murat

Or maybe: /Users/murat (if you’re on a Mac)

Or even: /home/murat/projects/my-blog (if you’re in a specific project folder)

What is this string of text? This is your absolute path. It’s your exact address in the computer’s file system, starting from the very beginning.

Let’s dissect that path, /home/murat/projects, because understanding this is the key to everything.

  • / (The Root): This first slash is “The Root Directory.” It is the absolute “lobby” of your entire system. Everything, every file, every device, every folder, lives inside this /.
  • home: This is a directory inside /. By convention, this is where all the user accounts live.
  • murat: This is my home directory, living inside /home. When I log in, this is the “room” I start in.
  • projects: This is a directory I created inside my home directory to keep my work organized.

pwd just told me, with zero ambiguity, that I am currently “standing” in the projects room, which is inside the murat room, which is inside the home room, which is in the lobby.

That’s it. That’s the whole command.

…or is it?

The shell (Bash) doesn’t actually have to “ask” the system where it is every time. It’s smart. It keeps track of your location in a special variable.

Try this:

# 'echo' just prints whatever you give it
# '$PWD' is the variable that stores your path
echo $PWD

The output will be… identical: /home/murat/projects

So, what’s the difference? Why have a command and a variable? 99% of the time, they are the same. But they can be different in one very tricky, specific, and important case: Symbolic Links (symlinks).

A symlink is just a “shortcut” or “portal” from one directory to another.

Watch what happens. Let’s create a “real” directory and a “link” to it.

# 1. Create a "real" directory somewhere
mkdir -p /tmp/my-real-data

# 2. Create a "link" (shortcut) to it in our home directory
# ln -s [target] [link-name]
ln -s /tmp/my-real-data ~/my-link

# 3. Now, "change directory" (cd) into the *link*
cd ~/my-link

Okay, now we’re “standing” inside ~/my-link. Where are we? Let’s ask our two “GPS” systems:

# Ask the shell's variable
echo $PWD

Output: /home/murat/my-link

The shell’s variable, $PWD, reports our logical path. It’s telling us the path we typed to get here. This is often what you want to see, as it’s less confusing.

Now, let’s ask the pwd command, but with a special flag: -P (for “Physical”).

# Ask 'pwd' to resolve all links and show the PHYSICAL path
pwd -P

Output: /tmp/my-real-data

Mind-bending, right? We are in two places at once.

  • Logically ($PWD or pwd -L): We are at /home/murat/my-link.
  • Physically (pwd -P): We are actually at /tmp/my-real-data.

The pwd command (by default, it often acts like pwd -L) tells you the “logical” path, but its true power—and its difference from echo $PWD—is its ability to resolve those “portals” and tell you where you physically are on the hard drive.

Why does this matter? Because scripts, permissions, and disk-space tools only care about the physical path. If you’re trying to debug why a script can’t write to a file, you must know the physical path. pwd -P is the tool for the job.


Hitting The Wall 🧱

My “wall” with pwd wasn’t the command itself. It was my complete and total ignorance of the concept of a “working directory.” This cost me an entire weekend of my life.

I was in my second year of university, learning Python. I wrote a simple script, analysis.py. In the exact same folder, I had a data file, data.csv.

My directory: /home/murat/school/project-1/ Inside this folder:

  • analysis.py
  • data.csv

My Python code was simple: f = open('data.csv', 'r')

I was in my terminal, in my home folder (/home/murat). I ran my script like this:

python3 school/project-1/analysis.py

CRASH. FileNotFoundError: [Errno 2] No such file or directory: 'data.csv'

I stared at the screen in disbelief. “WHAT?! It’s RIGHT THERE! I’m looking at it! data.csv is right next to analysis.py!”

I re-ran the command. Crash. I rewrote the Python code. Crash. I renamed the file. Crash. I went absolutely insane. I was convinced the computer was broken, that Python was bugged, that my life was a lie. The file was there.

I showed my professor on Monday, full of despair. He looked at my screen, typed one command, and solved the entire problem.

First, he typed pwd. Output: /home/murat

Then he said: “The script is at /school/project-1/. But youyou are at /home/murat.”


The Breakthrough Moment ✨

The “Aha!” moment was so profound it changed my entire understanding of computing.

My professor explained: “A program inherits its ‘working directory’ from the shell that launches it. The program isn’t ‘in’ the folder /project-1/. The program is running ‘in’ /home/murat, because that’s where you were when you ran it.”

My script was looking for /home/murat/data.csv. That file didn’t exist.

My mind was blown. The “working directory” wasn’t a property of the script; it was a state of the shell.

He showed me the two solutions:

Solution 1 (The ‘Bad’ Way): Hard-code the absolute path in my script. f = open('/home/murat/school/project-1/data.csv', 'r') (This is brittle and breaks if you move the folder.)

Solution 2 (The ‘Right’ Way): Change your shell’s state before you run the script.

He typed this: cd school/project-1/

Then he typed pwd. Output: /home/murat/school/project-1/

“Now,” he said, “run your script from here.” python3 analysis.py

It worked.

pwd wasn’t just a “print” command. It was a diagnostic tool. It was the only tool that could have shown me why my mental model was wrong. I wasn’t just “running a script”; I was launching a process from a specific location in the file system. pwd was the command that told me that location.

From that day on, I never run a script without first asking, “Where am I?” pwd.


If this post has made you realize the file system is an “abstract map” you need to learn, my number one recommendation is “The Linux Command Line: A Complete Introduction” by William Shotts.

This is the book that takes the “map” that pwd shows you and turns it into a real city. Shotts patiently walks you through the Filesystem Hierarchy Standard (FHS). You’ll stop seeing /bin, /etc, /var, /tmp, and /home as just “random folders” and start understanding why they exist.

  • /bin is where the “binary” commands live.
  • /etc is where the “et cetera” system configuration files are.
  • /var is where “variable” data like logs are stored.

This book is what builds the mental model that pwd helps you navigate. It’s the guide that finally makes the “invisible city” visible. Amazon


Key Takeaways 📚

  1. 💡 pwd is Your Anchor. It stands for “Print Working Directory” and is your “You Are Here” sign in the abstract world of the terminal. Use it constantly. Before you run a script, before you delete a file, before you move a directory… pwd.
  2. ⚙️ A Process Inherits Its ‘Working Directory’ from the Shell. This is the root of 90% of all “File Not Found” errors. A script doesn’t “know” where it lives; it only knows where the shell was when it was launched.
  3. 📚 Use pwd -P to See the Physical Path. The shell’s $PWD variable (and pwd -L) shows you the logical path you typed, which can be a symlink. pwd -P (Physical) resolves all links and shows you where on the disk you actually are. This is the ultimate debugging tool for file system issues.

Thanks for Following ☕

☕ If you found this guide helpful, you can Buy Me a Coffee! Medium Etsy LinkedIn Read More

What was your “file not found” moment that was really a ‘pwd’ misunderstanding? Or what’s your favorite tool for visualizing the file system (like tree or exa)?