Skip to content
shellmap

cdChange the current working directory across all 5 shells

Equivalents in every shell

Bashunix
cd /path/to/dir
Zshunix
cd /path/to/dir
Fishunix
cd /path/to/dir
PowerShellwindows
Set-Location /path/to/dir

Aliased as `cd`, `chdir`, `sl`.

cmd.exewindows
cd /d D:\path\to\dir

`/d` is required when changing drives.

Worked examples

Go to home directory

Bash
cd
Fish
cd
PowerShell
cd ~
cmd.exe
cd %USERPROFILE%

Go to previous directory

Bash
cd -
Fish
cd -
PowerShell
cd -

Change to another drive

Bash
cd /mnt/d
PowerShell
cd D:
cmd.exe
cd /d D:\projects

Gotchas

  • In cmd, plain `cd D:\path` does NOT change drive — it just remembers the path on D:. Use `cd /d`.
  • PowerShell `cd -` requires PowerShell 6.2+; earlier versions need `Pop-Location` with a paired `Push-Location`.
  • Fish has `cd -` and also remembers a directory stack via `cdh`/`prevd`/`nextd`.

WSL & PowerShell Core notes

pwsh`cd` is an alias for `Set-Location` on every pwsh platform, but path syntax does not travel: `cd C:\work` only makes sense on Windows, and `cd /usr/local` only on Linux/macOS. `cd ~` resolves to the OS-native home directory on each (`C:\Users\<name>`, `/home/<name>`, `/Users/<name>`), so scripts that use `~` stay portable. Drive switching is also Windows-only — `cd D:` jumps to the last-known directory on D:, while Linux/macOS pwsh hosts have no drive concept and will throw `Cannot find path` on a drive-letter argument.
WSLPath translation is the constant friction. WSL sees Windows drives mounted at `/mnt/c/`, `/mnt/d/`, ... so `cd /mnt/c/Users/me/code` is the WSL form of `C:\Users\me\code`. Use `wslpath` to convert in either direction: `cd "$(wslpath 'C:\Users\me\Downloads')"`. From Windows-side PowerShell into WSL files, use the UNC form `cd \\wsl$\Ubuntu\home\me`. Working directory is preserved across the boundary: running `wsl.exe` from a Windows shell at `C:\work` lands you in `/mnt/c/work` inside WSL, and `cmd.exe /c` from inside WSL at `/mnt/c/work` lands the cmd shell at `C:\work`.

Related commands