Skip to main content

Command referencecd

cd command (Linux / bash / sh / zsh)

Linuxbashshzshfilebeginner

What it does

Change the shell's current working directory. When people search for the cd command linux, they usually want cd's everyday flags, safe examples, and how it differs from related tools. Below you'll find syntax, options, and copyable examples for Bash/sh/zsh.

Change the shell's current working directory.

Syntax

cd [DIRECTORY]

Common options

Flag / optionMeaning
-Return to the previous directory.
~Move to the current user's home directory.
..Move to the parent directory.

Practical examples

Open a project

cd ~/projects/site

Changes into a project below the home directory.

Go up

cd ..

Moves one directory level upward.

Return

cd -

Switches back to the previous working directory.

Linux ↔ Windows equivalent

Closest match: Set-Location (Windows / PowerShell). Change the current location to a path in a PowerShell provider.

Common mistakes

  • Running `cd` in a child script and expecting the parent shell directory to change.
  • Leaving paths containing spaces unquoted.

FAQ

What does cd do in Linux?

Change the shell's current working directory.

How do I use cd from the terminal?

Start with `cd [DIRECTORY]`, then choose only the options needed for the task.

What is a practical cd example?

Try `cd ~/projects/site` — Changes into a project below the home directory.

Can I use cd in a shell script?

Yes. cd works in Bash, sh, and Zsh, but scripts should handle quoting, errors, and command output explicitly.

Browse the full Linux and Windows command reference to search more bash, CMD, PowerShell, Conda, and GitHub CLI commands.