Skip to content
shellmap

set-locationChange directory — navigates filesystem and other providers across all 5 shells

Equivalents in every shell

Bashunix
cd /var/log

Builtin. Bare `cd` jumps to `$HOME`; `cd -` returns to the previous directory (`$OLDPWD`). Path arguments respect `$CDPATH` for "search common parents" behaviour. Symlinks are followed by default; pass `cd -P` to canonicalise to the physical (resolved) path.

Zshunix
cd /var/log

Builtin. Identical to bash plus a directory stack: `cd +1` … `cd +9` (or `cd -N`) jump to entries from `dirs -v`. Set `AUTO_PUSHD` in `.zshrc` to make every `cd` push onto the stack automatically.

Fishunix
cd /var/log

Builtin. `cd -` returns to the previous directory; `cdh` opens an interactive picker over recently-visited directories. Fish has no `$CDPATH`; instead use `set -gx CDPATH ~/projects /etc` for the same parent-search behaviour.

PowerShellwindows
Set-Location C:\Users

Aliased as `cd`, `chdir`, `sl`. Works on every PowerShell PROVIDER, not just the file system — `Set-Location HKLM:\Software\Microsoft` walks the registry. Use `-LiteralPath` for paths containing wildcard characters (`[`, `]`).

cmd.exewindows
cd /d D:\projects

Built-in. Plain `cd D:\path` only REMEMBERS the path on D: without switching drives — `/d` is required to actually change drive. `cd` with no args prints the current path (NOT $HOME like Unix).

Worked examples

Change to the parent directory

Bash
cd ..
PowerShell
Set-Location ..
cmd.exe
cd ..

Jump to home directory

Bash
cd
Fish
cd
PowerShell
Set-Location ~
cmd.exe
cd %USERPROFILE%

Navigate into the Windows registry

PowerShell
Set-Location HKLM:\Software\Microsoft\Windows

Gotchas

  • `Set-Location` is provider-aware: `Set-Location HKLM:` enters the registry, `Set-Location Cert:` enters the certificate store. Bash users expecting cd to only touch files are surprised when `Get-ChildItem` after `cd HKLM:` returns registry keys, not file entries.
  • The `cd` alias is unchanged on Linux/macOS pwsh hosts — it still calls `Set-Location` rather than dropping to a system `cd` (which doesn't exist as a binary anyway, since `cd` is a bash builtin). Scripts that expect bash semantics need to use `bash -c 'cd … && …'` explicitly.
  • `Set-Location -` (previous directory) requires pwsh 6.2+. On Windows PowerShell 5.1, use `Push-Location` / `Pop-Location` to maintain a manual stack, or set `$PWD.PreviousPath` yourself.
  • Wildcards: `Set-Location ~\Down*` works (resolves to `~\Downloads` if unique); if it matches more than one path, the cmdlet errors. Always pass `-LiteralPath` when a directory name contains `[` or `]`.
  • Provider state is per-runspace: in `ForEach-Object -Parallel` (pwsh 7+), each parallel thread starts with the runspace's initial location, NOT the caller's current location. Pass `$using:PWD` and re-`Set-Location` inside the block if you need shared cwd.

WSL & PowerShell Core notes

pwsh`Set-Location` works on every pwsh platform against the file-system provider, plus Windows-only providers (registry, certificate store, IIS). On Linux/macOS pwsh hosts only the file-system provider exists, so `Set-Location HKLM:` errors with `Cannot find drive`. Path separators are normalised — `Set-Location /usr/local` works on Windows pwsh (resolves to `C:\usr\local`) and `Set-Location C:\` works on Linux pwsh (errors as expected).
WSLFrom Windows-side pwsh, `Set-Location \\wsl$\Ubuntu\home\me` (UNC form) enters a WSL distro's filesystem. From inside WSL bash, `cd /mnt/c/Users/me` enters the Windows side via DrvFs. Use `wslpath` to translate paths in either direction. Working directory is preserved across interop boundaries: running `wsl.exe` from Windows pwsh at `C:\work` lands inside WSL at `/mnt/c/work`.

Related commands