pwd - Where Am I?

pwd stands for Print Working Directory. It tells you exactly where you are in the file system.

The Command

Terminal
$pwd
/home/user

That's it. No flags, no options, just pwd. It prints the absolute path of your current directory.

Why It Matters

When you're jumping between directories, especially across multiple terminal sessions, it's easy to lose track of where you are.

hljs bash
# You've been navigating for a while...
cd projects
cd ../Documents
cd ~/Downloads
cd -

# Wait, where am I now?
pwd     # Answer: /home/user/Documents

Check Before You Delete

Before running any destructive command (rm, mv), run pwd first. Deleting files in the wrong directory is a mistake you only make once.

pwd in Scripts

In shell scripts, pwd is often used to get the current directory into a variable:

hljs bash
current_dir=$(pwd)
echo "Running from: $current_dir"

Or combined with other commands:

hljs bash
# Create a log file in the current directory
echo "Process started" > "$(pwd)/process.log"

Physical vs Logical Paths

pwd has two options:

  • pwd -L - Logical path (default) - shows the path with symlinks
  • pwd -P - Physical path - shows the actual path, resolving symlinks
Terminal
$# If /home/user/current is a symlink to /var/www/html:
$cd /home/user/current
$pwd
/home/user/current
$pwd -P
/var/www/html

Most of the time, the default is what you want. Use -P when you need the real location.

The Prompt Shows It Too

Remember the prompt from Chapter 1?

user@hostname:~/projects$

The ~/projects part is your current directory. But it's often abbreviated:

  • ~ = /home/user
  • ~/projects = /home/user/projects

pwd gives you the full, unabbreviated path.

Knowledge Check

What does pwd stand for?

Key Takeaways

  • pwd prints your current directory's absolute path
  • Run it before destructive operations to confirm your location
  • Use pwd -P to resolve symbolic links
  • Your prompt usually shows an abbreviated version of the same info

Short and simple. Next: ls - the command you'll use a hundred times a day.