Python Current Directory: pwd & $PWD Variable
The `pwd` (print working directory) command prints the full pathname of the current working directory. By default, `pwd` resolves symbolic links logically (`pwd -L`); using `pwd -P` reveals the physical canonical disk path.
"If a street has a nickname (symbolic link), `pwd -L` reads the street nickname sign, while `pwd -P` checks the official municipal land registry parcel number."
Deep Dive: How It Works
Logical vs Physical: Symlinks create virtual path aliases. `-L` follows symlink names, while `-P` resolves real physical target locations.
$PWD and $OLDPWD: Shell environment variables automatically maintained by Bash upon every `cd` invocation.
Script Context: `SCRIPT_DIR=$(cd "$(dirname "$0")" && pwd)` is the standard POSIX pattern to find where a script file lives on disk.
Syntax Blueprint
pwd # Logical path ($PWD) pwd -P # Physical resolved path without symlinks echo "$PWD" # Fast internal variable lookup
Use pwd -P when your script needs the true physical file location without symbolic redirects.
Core Rules to Remember



Common Beginner Traps & How to Fix Them
Assuming $PWD is identical to physical path when symlinked folders are involved.Why it happens: Bash preserves symlink structure in $PWD by default.
How to fix: Use `pwd -P` or `realpath .` to obtain the true hardware path.
Live Interactive Example
Hit Run Code to see it liveYour Turn: Micro Challenge
No pressure! Edit the starter code below and test your solution with instant feedback.
Print Current Directory with PWD
Print the value of the environment variable `$PWD` using echo.
Finished reading and practicing?
Mark this lesson as completed to update your course progress.