pwd Command Cheat Sheet
pwd stands for Print Working Directory. It displays the full absolute path of the current location.
Synopsis
pwd [OPTION]...
Basic Usage
pwd
# Output: /home/user/projects
Symlinks: Physical vs Logical
Suppose /var/www is a symlink to /mnt/storage/www.
cd /var/www
Logical Path (-L)
Returns the path including the symlink (what you typed). This is the default.
pwd -L
# Output: /var/www
Physical Path (-P)
Resolves all symlinks to the actual physical location on disk.
pwd -P
# Output: /mnt/storage/www
Use in Scripts
Store current directory in a variable.
CURRENT_DIR=$(pwd)
echo "Running in $CURRENT_DIR"
Notes
- $PWD: The shell maintains the environment variable
$PWD, which is equivalent topwd -L. pwdis usually a shell builtin (runs fast inside bash), but there is also a binary/bin/pwd. To run the binary specifically (rare), use/bin/pwd.