Overview
cd is a shell builtin because changing directory must affect the current shell. A separate executable cannot change its parent shell's directory. This reference documents Bash behavior; another shell can differ.
Background
cd is a shell builtin, not a separate program: the Bash manual lists it among the Bourne shell builtins. It has to be built in because the working directory belongs to the shell process, and a separate program could only change its own. Each shell supplies its own cd, so behaviour such as cd - and -P is a property of the shell, not of the operating system.
Examples
Move into a project directory:
cd projects
Move to the parent directory:
cd ..
Return to your home directory:
cd
Go to a directory under your home directory with the tilde shortcut:
cd ~/projects
Change directory and show where you ended up, stopping if the change fails:
cd projects && pwd
Common mistakes
Quote directory names containing spaces: cd 'project notes'. Chain with && rather than ; so later commands do not run in the wrong directory after a failed cd. A CDPATH variable can make cd name resolve somewhere unexpected. Your current directory changes how relative paths are interpreted. Confirm your location with pwd before running a command that modifies files.
Portability
A standalone explain binary cannot inspect your parent shell's aliases, functions, or exact builtin implementation. Zsh and dash builtins also exist and are not covered or tested here. Choose Bash explicitly when needed; a detected SHELL environment variable is not proof of the active shell.
About Bash cd
These examples describe the cd built into Bash and were executed on Bash 5.2.37. Other shells such as zsh and dash have their own cd, which this page has not checked.
Bash examples
Return to the previous directory:
cd -
Bash uses OLDPWD for this shortcut and prints the new directory.
Resolve symbolic links to the physical directory:
cd -P projects
Options
-P
Resolve symbolic links physically rather than retaining their logical path. pwd -P can help compare
the physical location.
-L
Follow logical directory paths, preserving symbolic-link components when processing the path. This
is Bash's default behavior.
References
Original explanations, with upstream documentation for further reading. FreeBSD references are comparison material, not a claim of Apple version equivalence.