pop-location — Return to the directory most recently pushed (PowerShell popd) across all 5 shells
Equivalents in every shell
popdbash built-in. Pops the top of the directory stack and cd's into it. `popd +N` pops the Nth entry from the top (not the one at index N). Stack is per-shell; popping an empty stack is an error.
popdzsh built-in. Identical to bash semantics. With `setopt AUTO_PUSHD` (every cd auto-pushes), `popd` becomes essentially "back" (undo the last cd) — a common interactive workflow.
popdfish built-in. No surprises; matches bash. Fish's tab-completion of stack entries (`cd -<TAB>`) gives you an interactive picker if you want to pop NOT the top.
Pop-LocationAliased as `popd`. `-StackName "foo"` (pwsh 6+) pops from a named stack (must match the `Push-Location -StackName` that pushed). Pops the most-recently-pushed entry — there's no `popd +N` syntax; use `(Get-Location -Stack)[N]` + `Set-Location` for arbitrary stack-position access.
popdcmd built-in. If the most-recent push was a UNC path (`pushd \\server\share`), `popd` AUTOMATICALLY un-maps the temporary drive letter. If you `net use Z:` something while pushed, `popd` does NOT clean it up — you have to `net use Z: /delete` manually.
Worked examples
Return to wherever you came from
popdPop-LocationpopdPop from a named stack (isolating script state)
# No named-stack support — use a subshellPop-Location -StackName myScriptInspect the stack before popping
dirs -v && popdGet-Location -Stack; Pop-Locationpushd && popdGotchas
- Popping an empty stack: bash and zsh print `popd: directory stack empty` (non-zero exit code); pwsh throws `Cannot pop the location because the stack is empty` (catchable exception); cmd silently does nothing. For cross-shell scripts, check before popping: bash `[ ${#DIRSTACK[@]} -gt 1 ] && popd` / pwsh `if (Get-Location -Stack) { Pop-Location }`.
- pwsh `Pop-Location -StackName` errors if the named stack is EMPTY OR DOESN'T EXIST — not the same as "no-op if missing". Wrap in `try { Pop-Location -StackName x } catch { Write-Verbose "stack empty" }` if it might not be present.
- cmd `popd` after a `pushd \\server\share` un-maps the temporary drive letter — but if you `cd Z:\elsewhere` while in the pushed state and then `popd`, the un-map still happens and you're unexpectedly back at the original directory with Z: gone. Cmd doesn't track that you moved off the pushed drive.
- On Linux/macOS pwsh, `popd` aliases to `Pop-Location` — so bash-builtin features like `popd +2` (pop the Nth entry) don't work. For bash semantics from pwsh, shell out: `bash -c "popd +2"`.
- Long-running pwsh sessions with unnamed-stack pushes that never get popped accumulate stack entries forever — `Get-Location -Stack` shows everything pushed since session start. Periodically drain: `while ((Get-Location -Stack).Count -gt 0) { Pop-Location }`.