pwd - Where Am I?
pwd stands for Print Working Directory. It tells you exactly where you are in the file system.
The Command
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.
# 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:
current_dir=$(pwd)
echo "Running from: $current_dir"
Or combined with other commands:
# 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 symlinkspwd -P- Physical path - shows the actual path, resolving symlinks
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.
What does pwd stand for?
Key Takeaways
pwdprints your current directory's absolute path- Run it before destructive operations to confirm your location
- Use
pwd -Pto 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.