Skip to content
shellmap

popdPop the top directory off the directory stack and cd into it across all 5 shells

Equivalents in every shell

Bashunix
popd

Builtin. Removes the top entry from the directory stack and changes directory to it. Errors if the stack is empty.

Zshunix
popd

Same as bash. `popd +N` removes the Nth entry without cd-ing into it.

Fishunix
popd

Builtin. Operates on fish's own directory stack — independent from bash or zsh stacks even in the same terminal.

PowerShellwindows
Pop-Location

Aliased as `popd`. Pops the top entry from the Location stack and changes location. `Pop-Location -StackName work` pops from a named stack other than the default.

cmd.exewindows
popd

Built-in. If the matching `pushd` had created a temp drive letter (for a UNC path), `popd` also DELETES that drive-letter mapping — important cleanup detail.

Worked examples

Return to where you were before the last pushd

Bash
popd
Zsh
popd
Fish
popd
PowerShell
Pop-Location
cmd.exe
popd

Pop without changing directory (just remove the top entry)

Bash
popd -n
Zsh
popd -n

Pop a specific entry from the stack

Bash
popd +1
Zsh
popd +1

Gotchas

  • `popd` on an empty stack is an error — `bash: popd: directory stack empty`. In scripts, guard with `[ ${#DIRSTACK[@]} -gt 1 ] && popd` (bash) before calling.
  • Calling `popd` does not consistently run shell `cd` hooks (zsh `chpwd`, fish `--on-variable PWD` handlers) across shells. If you rely on a hook to set up environment per directory, double-check it actually fires after `popd`.
  • PowerShell's `Pop-Location -StackName work` pops from a NAMED stack — if you pushed to a named stack and forget to specify the name on pop, you'll pop from the default (empty) stack and get an error.
  • Cmd `popd` removes any temp drive letter created by the matching `pushd`. Scripts that exit without `popd` leak the mapping until the next reboot or a manual `net use /delete`.
  • Fish `popd` errors silently if its own stack is empty on some versions — no message, only a non-zero `$status`. Combine with `count (dirs)` defensively in scripts.

WSL & PowerShell Core notes

pwsh`popd` ships as a built-in alias for `Pop-Location` on both Windows and Unix pwsh, so bash muscle-memory carries over. The Location stack is per-pwsh-process and does NOT survive shell exit, unlike bash `DIRSTACK` which can be persisted via shell rc files.
WSLWSL bash and Windows pwsh maintain SEPARATE directory stacks — a `pushd` from pwsh is invisible to `popd` inside WSL and vice versa. There is no shared cross-shell stack; bridging requires writing the path through `$WSLENV` or a file in `/mnt/c`.

Related commands