Skip to content
shellmap

pushdPush the current directory onto a stack and cd into a new one across all 5 shells

Equivalents in every shell

Bashunix
pushd /tmp

Builtin. Adds the new directory to the directory stack, then `cd`s into it. View the stack with `dirs`; pop with `popd`.

Zshunix
pushd /tmp

Same as bash. Zsh adds an `AUTO_PUSHD` option (`setopt auto_pushd`) that pushes on EVERY `cd` automatically — useful for navigating back through recent directories.

Fishunix
pushd /tmp

Builtin. Fish maintains its own per-shell directory stack; `dirs` lists it.

PowerShellwindows
Push-Location /tmp

Aliased as `pushd`. Pushes onto a per-runspace Location stack; view with `Get-Location -Stack`. Works with PSDrives like `Push-Location HKCU:\Software` — even unrelated providers.

cmd.exewindows
pushd C:\Users

Built-in. For UNC paths (`pushd \\server\share`), cmd auto-mounts the share to a temporary drive letter (Z:, Y:, …) — `popd` later removes it. A poor-man's `net use`.

Worked examples

Save the current directory and switch to /tmp

Bash
pushd /tmp
Zsh
pushd /tmp
Fish
pushd /tmp
PowerShell
Push-Location /tmp
cmd.exe
pushd C:\Temp

Push current directory but stay where you are (no cd)

Bash
pushd -n .
Zsh
pushd -n .

Rotate the directory stack so the Nth entry becomes the top

Bash
pushd +2
Zsh
pushd +2

Gotchas

  • `pushd` with NO ARGUMENTS swaps the top two entries on the stack — calling it twice returns you to where you started. This is the bash/zsh `cd -` equivalent for a back-and-forth toggle.
  • Zsh's `setopt auto_pushd` quietly pushes EVERY `cd` onto the stack, so `dirs -v` listings grow unboundedly during a long session. Pair with `setopt pushd_ignore_dups` to keep the stack tidy.
  • Cmd `pushd \\server\share` creates a temp drive letter behind the scenes. If the process exits abnormally without `popd`, that mapping LEAKS until you `net use Z: /delete` manually or reboot.
  • PowerShell `Push-Location` stack is PER-RUNSPACE, not per-session — opening a new tab gets a fresh empty stack. The `-StackName work` variant lets you keep several named stacks in parallel.
  • Fish doesn't share its directory stack with bash/zsh — each shell has its own. Switching shells loses the in-memory stack; only the final `pwd` carries over to the next shell.

WSL & PowerShell Core notes

pwshOn both Windows and Unix pwsh, `pushd` is an alias for `Push-Location` (NOT the cmd builtin, even when launched from cmd). PowerShell `Push-Location` understands PSDrive paths (`Push-Location HKLM:\Software`, `Push-Location Cert:\CurrentUser`) — there is no Unix-shell equivalent for non-filesystem stacks.
WSLInside WSL, `pushd /mnt/c/Users` works, but DrvFs makes subsequent operations on the pushed directory roughly 10× slower than native Linux paths. Prefer pushing to the WSL home filesystem when the workflow allows.

Related commands