Quick take: The pwd command prints the full path of your current working directory. Plain pwd shows the logical path (following symlinks as taken), while pwd -P shows the physical path with symlinks resolved.
Introduction
The pwd command (print working directory) tells you exactly where you are in the filesystem. It seems trivial, but it is essential for orientation in deep directory trees and is widely used in scripts to record or act on the current location.
Syntax
The basic syntax of the pwd command is:
pwd [OPTIONS]Common Options and Parameters
The most useful options and parameters for the pwd command:
| Option | Description |
|---|---|
| (default) | Print the logical working directory (-L). |
| -L | Logical path — keep symlink names as you navigated them. |
| -P | Physical path — resolve all symlinks to the real path. |
Practical Examples
Real pwd commands you can run today:
# Print the current directory
pwd
# Print the real path with symlinks resolved
pwd -P
# Store the current directory in a variable
current=$(pwd)
# Use in a script to reference files relative to here
echo "Running from $(pwd)"Tips and Best Practices
- Inside a symlinked directory,
pwdshows the path you took whilepwd -Pshows the real underlying path. - In scripts,
$(pwd)captures the current directory, though$PWD(a shell variable) is faster and avoids spawning a process. - Combine with
cd -to bounce between two directories while keeping track of where you are.
Final Thoughts
pwd answers the simplest but most frequent question on the command line: “where am I?” Remember -P to resolve symlinks to the true path, and reach for $PWD in scripts. It is a small command, but orientation is the foundation of confident navigation.
FAQ: pwd Command in Linux
What does pwd do in Linux?+
pwd prints the full absolute path of the directory you are currently in — your working directory — which is essential for orientation in the filesystem.
What is the difference between pwd -L and pwd -P?+
pwd -L (the default) prints the logical path, keeping symlink names as you navigated them. pwd -P prints the physical path with all symlinks resolved to the real location.
How do I use pwd in a script?+
Capture it with command substitution: current=$(pwd). The shell also provides the $PWD variable, which holds the same value without running a command.
Why does pwd show a different path than I expect?+
You likely entered a directory through a symlink. pwd shows the symlinked path by default; run pwd -P to see the real underlying directory.
Is pwd a shell built-in?+
Yes, pwd is a shell built-in, and the shell also keeps the current directory in the $PWD environment variable, which you can read directly.
Need help with Linux servers or infrastructure?
Work directly with Muhammad Irfan Aslam for Linux, Ubuntu, Docker, DevOps, cloud, CI/CD, or infrastructure support.
Hire Me for Support