dirs — List the directory stack built up by pushd and popd across all 5 shells
Equivalents in every shell
Bashunix
dirs -vBuiltin. `-v` shows the indexed (vertical) form — the indices are what you pass to `pushd +N` / `popd +N`. `dirs -c` clears the stack.
Zshunix
dirs -vSame as bash. With `setopt auto_pushd`, `dirs` effectively becomes a recent-cd history.
Fishunix
dirsBuiltin. No `-v` flag — fish prints the stack one entry per line by default, oldest first.
PowerShellwindows
Get-Location -StackNo `dirs` alias. `Get-Location -Stack` returns a stack of `PathInfo` objects (with `.Path` per entry), not plain text — project with `| ForEach-Object Path` to get bash-style output.
cmd.exewindows
pushd`pushd` with no arguments lists the current stack — same output format `pushd` would print after a push. There is no separate `dirs` keyword in cmd.
Worked examples
Show the directory stack with indices
Bash
dirs -vZsh
dirs -vFish
dirsPowerShell
Get-Location -Stack | ForEach-Object Pathcmd.exe
pushdClear the directory stack
Bash
dirs -cZsh
dirs -cPowerShell
while (Get-Location -Stack) { Pop-Location }Print just the depth of the directory stack
Bash
dirs | wc -wZsh
echo ${#dirstack[@]}PowerShell
(Get-Location -Stack).CountGotchas
- `dirs` always prefixes the listing with the current `$PWD` — so a single-entry stack still shows two paths if you've been `cd`-ing manually. To see only the explicit pushes, use `dirs -v` and ignore index 0.
- Zsh's `auto_pushd` makes `dirs` essentially a directory history, but DUPLICATES pile up unless you also `setopt pushd_ignore_dups`. Untuned, `dirs` becomes useless after a busy session.
- PowerShell `Get-Location -Stack` returns OBJECTS, not strings — string concatenation (`"current: " + (Get-Location -Stack)`) silently produces `Microsoft.PowerShell.Commands.PSCommandLocationStack`. Always project a property.
- Cmd has no way to clear the directory stack other than repeatedly calling `popd` until the stack is empty (which errors at the bottom). Closing the cmd window is the only sure reset.
- Fish `dirs` prints in oldest-first order — the OPPOSITE of bash `dirs` which is newest-first. Scripts that parse the output need to know which shell they are running under.
WSL & PowerShell Core notes
pwsh`dirs` is NOT an alias on pwsh — `Get-Location -Stack` is the only built-in equivalent on both Windows and Unix. Add `Set-Alias dirs "Get-Location -Stack"` (or a wrapper function for projection) in `$PROFILE` if you want bash muscle-memory; PSReadLine ships no such alias by default.
WSLWSL bash `dirs` lists the WSL session's stack only — it cannot see pushes made by the parent Windows pwsh/cmd. To inspect both, run `dirs` inside WSL and `Get-Location -Stack` in pwsh separately and concatenate the output yourself.