How to Get the Current Folder in the Terminal with pwd
Every terminal works in a folder, and many commands need its full path: to set a variable to "this folder", to copy a path into a config file, or just to check where you are. pwd prints it, and $PWD puts it straight into another command. This guide shows both in zsh, bash and PowerShell.
Syntax
In zsh and bash:
pwd
echo "$PWD"
<command> "$PWD/<something>"
| Part | What it means |
|---|---|
pwd | Prints the full path of the current folder |
$PWD | A variable that holds the same path, for use inside other commands |
The zsh manual describes PWD as "The present working directory. This is set when the shell initializes and whenever the directory changes."
In PowerShell:
"$PWD"
Get-Location
Microsoft's documentation says $PWD "Contains a path object that represents the full path of the current directory location".
The Example
You print the folder the terminal is in, then create a reports folder, move into it, and print the path again.
Step 1: Print the Current Folder
- macOS / Linux
- Windows (PowerShell)
echo "$PWD"
pwd
mkdir -p reports
cd reports
echo "$PWD"
/Users/you/source/shell-demo
/Users/you/source/shell-demo
/Users/you/source/shell-demo/reports
"$PWD"
Get-Location
/Users/you/source/shell-demo
Path
----
/Users/you/source/shell-demo

pwd and $PWD gave the same path. After cd reports, $PWD changed with it. In PowerShell, "$PWD" gives the path as text, while Get-Location prints it as a small table with a Path column. On Windows, the paths are Windows paths.
Using It in Another Command
Because $PWD is a variable, it can go anywhere a path can. A common use is pointing a tool at the folder you're in:
export APP_HOME="$PWD"
That stores the current folder's full path in APP_HOME for every program you start from this terminal. Keep the double quotes, so a path with spaces stays one piece.
Common Mistakes
| Mistake | What happens | Do this instead |
|---|---|---|
$pwd in lowercase in zsh or bash | Names are case-sensitive there, so it's a different, unset variable | $PWD |
Leaving out the quotes: export APP_HOME=$PWD | Works until a folder name has a space | "$PWD" |
Troubleshooting
| Symptom | Likely cause | Fix |
|---|---|---|
| The path isn't the folder you expected | The terminal is somewhere else | cd to the right folder first, then use $PWD |
FAQ
What's the difference between pwd and $PWD?
pwd is a command that prints the path. $PWD is a variable holding it, which you can use inside other commands without running anything.
Does $PWD follow cd?
Yes, as Step 1 showed: it changed to .../reports right after cd reports.
Conclusion
pwd and $PWD both gave /Users/you/source/shell-demo, and $PWD followed cd into reports. Use "$PWD" whenever a command needs the full path of the folder you're in.
Additional Resources
- zsh parameters set by the shell —
PWDand its relatives. - about_Automatic_Variables — PowerShell's
$PWD.
