cd command (Linux / bash / sh / zsh)
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 / option | Meaning |
|---|---|
| - | 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.
Related commands
- pwdPrint the absolute path of the current working directory.
- lsList directory entries and inspect file metadata.
- Set-LocationChange the current location to a path in a PowerShell provider.
- dirList files and subdirectories with names, dates, sizes, and attributes.
- findWalk directory trees and select entries using tests and actions.
- Get-ChildItemEnumerate items and child items in filesystem, registry, and other providers.
- cdDisplay or change the current directory in Command Prompt.
- rmRemove files and directory trees permanently.
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.